encodeCall method
Encodes a call to this function with the specified parameters for a transaction or a call that can be sent to the network.
The params
must be a list of dart types that will be converted. The
following list shows what dart types are supported by what solidity/abi
parameter types.
- arrays (static and dynamic size), unless otherwise specified, will
accept a dart List of the type of the array. The type "bytes" will
accept a list of ints that should be in
0; 256
. - strings will accept an dart string
- bool will accept a dart bool
- uint
Other types are not supported at the moment.
Implementation
Uint8List encodeCall(List<dynamic> params) {
if (params.length != parameters.length) {
throw ArgumentError.value(
params.length,
'params',
'Must match function parameters',
);
}
final sink = LengthTrackingByteSink()
//First four bytes to identify the function with its parameters
..add(selector);
TupleType(parameters.map((param) => param.type).toList())
.encode(params, sink);
return sink.asBytes();
}