call method
- EthereumAddress contractAddress,
- ContractAbi abi,
- String methodName,
- {List? params,
- EthereumAddress? sender}
Performs a static call to a contract method.
contractAddress
: The address of the contract.abi
: The ABI (Application Binary Interface) of the contract.methodName
: The name of the method in the contract.params
: Additional parameters for the method.sender
: Additional sender for the transaction.
Returns a list of dynamic values representing the result of the static call.
Implementation
Future<List<dynamic>> call(
EthereumAddress contractAddress, ContractAbi abi, String methodName,
{List<dynamic>? params, EthereumAddress? sender}) {
final function = getContractFunction(methodName, contractAddress, abi);
final calldata = {
'to': contractAddress.hex,
'data': params != null
? bytesToHex(function.encodeCall(params),
include0x: true, padToEvenLength: true)
: "0x",
if (sender != null) 'from': sender.hex,
};
return _provider.send<String>('eth_call', [calldata]).then(
(value) => function.decodeReturnValues(value));
}