call method

Future<EtherScanRpcResponseModel> call({
  1. required String? to,
  2. required String? data,
  3. String? tag,
})

Executes a new message call immediately without creating a transaction on the block chain

to - Address to execute from

data - Data to transfer

tag - A tag

Example

var res = eth.call(
    to: '0xAEEF46DB4855E25702F8237E8f403FddcaF931C0',
    data: '0x70a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724',
    tag: 'latest'
);

Implementation

Future<EtherScanRpcResponseModel> call({
  required String? to,
  required String? data,
  String? tag,
}) async {
  const module = 'proxy';
  const action = 'eth_call';

  Map<String, dynamic>? query = {
    'apiKey': apiKey,
    'module': module,
    'action': action,
    'to': to,
    'data': data,
  };

  if (tag != null) {
    query.putIfAbsent('tag', () => tag);
  }

  return (await get(query)).fold(
    (l) => EtherScanRpcResponseModel.empty(),
    (r) => EtherScanRpcResponseModel.fromJson(r),
  );
}