From 7dfa8abedca1aaf542f091dcdc3d40b4bd078d46 Mon Sep 17 00:00:00 2001 From: Josue Date: Sat, 12 Aug 2023 17:37:51 -0700 Subject: [PATCH] Exposing _call so we can sign typed data (EIP712) This way we can sign typed data like this: ``` await provider.getSigner().call("_signTypedData", [ jsify(domain), // jsify is required in case not being primitives jsify(types), jsify(value) ]); // returns "0x..." signature hex ``` --- lib/src/ethers/signer.dart | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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.