readContract static method
Read contract
address
is public address
value
is the value sent with this transaction.
contractAddress
is contract address
methodName
is a contract method name, such as 'mint', 'balanceOf'
parameters
is parameters required by the method
abiJsonString
is abi json string, such as "[{"inputs":{\"internalType\":\"uint256\",\"name\":\"quantity\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}
,"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"}]"
Implementation
static Future<dynamic> readContract(
String address,
BigInt value,
String contractAddress,
String methodName,
List<Object> parameters,
String abiJsonString) async {
final valueHex = "0x${value.toRadixString(16)}";
final data = await EvmService.customMethod(
contractAddress, methodName, parameters, abiJsonString);
final req = RequestBodyEntity();
req.chainId = await ParticleBase.getChainId();
const method = "eth_call";
final params = [
{"from": address, "to": contractAddress, "data": data, "value": valueHex},
"latest"
];
final result = await EvmService.rpc(method, params);
return result;
}