rawCall<String> method

Future<String> rawCall<String>({
  1. TransactionRequest? transactionRequest,
  2. TransactionResponse? transactionResponse,
  3. dynamic blockTag,
})

Returns the result of executing the transaction in raw hex string, using either transactionRequest or transactionResponse.

A call does not require any ether, but cannot change any state. This is useful for calling getters on Contracts.


final supp = await provider!.rawCall(
  transactionRequest: TransactionRequest(
    to: '0xed24fc36d5ee211ea25a80239fb8c4cfd80f12ee', // Some random ERC20 contract
    data: '0x18160ddd', // Function signature of totalSupply()
  ),
); // 0x0000000000000000000000000000000000000000000d3c21bcecceda10000000

BigInt.parse(supp); // 16000000000000000000000000

Implementation

Future<String> rawCall<String>({
  TransactionRequest? transactionRequest,
  TransactionResponse? transactionResponse,
  dynamic blockTag,
}) {
  assert((transactionRequest != null) ^ (transactionResponse != null),
      'Only use either transactionRequest or transactionResponse');
  return call<String>(
    'call',
    blockTag != null
        ? [transactionResponse?.impl ?? transactionRequest?.impl, blockTag]
        : [transactionResponse?.impl ?? transactionRequest?.impl],
  );
}