execute static method
Encodes a function call to execute a user operation in a smart wallet.
Parameters:
walletAddress
: TheEthereumAddress
of the smart wallet.to
: TheEthereumAddress
of the target recipient for the operation.amount
: TheEtherAmount
representing the amount to transfer, if applicable.innerCallData
: The Uint8List containing inner call data, if applicable.isSafe
: An optional flag indicating whether the operation is a GnosisSafeOperation or not. defaults to false.
Returns: A Uint8List containing the ABI-encoded data for the 'execute' function call.
Example:
var encodedCall = execute(
EthereumAddress.fromHex('0x9876543210abcdef9876543210abcdef98765432'),
to: EthereumAddress.fromHex('0x1234567890abcdef1234567890abcdef12345678'),
amount: EtherAmount.inWei(BigInt.from(1000000000000000000)),
innerCallData: Uint8List.fromList([]),
); // transfer to 0x1234567890abcdef1234567890abcdef12345678 with 1000000000000000000 wei
This method uses the 'execute' function ABI to encode the smart wallet operation.
Implementation
static Uint8List execute(EthereumAddress walletAddress,
{required EthereumAddress to,
EtherAmount? amount,
Uint8List? innerCallData,
bool isSafe = false}) {
final params = [
to,
amount?.getInWei ?? EtherAmount.zero().getInWei,
innerCallData ?? Uint8List.fromList([])
];
String method = 'execute';
if (isSafe) {
method = 'executeUserOpWithErrorString';
params.add(BigInt.zero);
}
return encodeFunctionCall(
method,
walletAddress,
ContractAbis.get(method),
params,
);
}