diff --git a/lib/src/ethers/signer.dart b/lib/src/ethers/signer.dart index 9cc1414..959f768 100644 --- a/lib/src/ethers/signer.dart +++ b/lib/src/ethers/signer.dart @@ -24,6 +24,36 @@ class Signer extends Interop { } } + /// Call Ethers provider [method] with [args] + Future call(String method, [List args = const []]) async { + try { + switch (T) { + case BigInt: + return (await call(method, args)).toBigInt as T; + default: + return await promiseToFuture(callMethod(impl, method, args)); + } + } catch (error) { + final err = dartify(error); + // debugPrint(stringify(error)); + switch (err['code']) { + case 4001: + throw EthereumUserRejected(); + default: + if (err['message'] != null) + throw EthereumException(err['code'], err['message'], err['data']); + else if (err['reason'] != null) + throw EthersException( + err['code'], + err['reason'], + err as Map, + ); + else + rethrow; + } + } + } + /// Connect this [Signer] to new [provider]. May simply throw an error if changing providers is not supported. Signer connect(Provider provider) => Signer._(impl.connect(provider.impl)); @@ -81,7 +111,7 @@ class Signer extends Interop { } /// Returns the result of calling using the [request], with this account address being used as the from field. - Future call(TransactionRequest request) => + Future rawCall(TransactionRequest request) => _call('call', [request.impl]); /// Returns the result of estimating the cost to send the [request], with this account address being used as the from field.