request<T> method
Use request to submit RPC requests with method
and optionally params
to Ethereum via MetaMask or provider that is currently using.
Returns a Future of generic type that resolves to the result of the RPC method call.
Implementation
Future<T> request<T>(String method, [dynamic params]) async {
try {
switch (T) {
case BigInt:
return BigInt.parse(await request<String>(method, params)) as T;
default:
return await promiseToFuture<T>(
callMethod(
impl,
'request',
[
_RequestArgumentsImpl(
method: method, params: params != null ? params : [])
],
),
);
}
} catch (error) {
final err = convertToDart(error);
switch (err['code']) {
case 4001:
throw EthereumUserRejected();
default:
if (err['message'] != null)
throw EthereumException(err['code'], err['message'], err['data']);
else
rethrow;
}
}
}