on master help sign in
metamask: send TX nonces as a string

Despite the Typescript compiler thinking that `web3.eth.sendTransaction` expects the `nonce` param as a type `number`, a `string` is actually required. Resolves this runtime error ``` inpage.js:1 MetaMask - RPC Error: Invalid transaction params: nonce is not a string. got: (471) {code: -32602, message: 'Invalid transaction params: nonce is not a string. got: (471)'} ```

commitfeb602ff97c768b9aa7d3ec3e4a79396e6bbbcd2 authortomholford <tomholford@users.noreply.github.com> dateFri 14 Jan 2022, 22:12 (5 years ago) parentfe5615c
1 file changed+7−1
src/lib/metamask.ts+7−1
src/lib/metamask.ts+7−1
@@ -27,7 +27,7 @@ const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
2727 data: data.toString(),
2828 gasLimit,
2929 gasPrice,
30− nonce: Number(nonce),
30+ nonce: Number(nonce).toString(),
3131 to: to.toString(),
3232 from: toHex(from),
3333 };
@@ -48,6 +48,12 @@ const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
4848 // signed tx, it makes us wait for confirmation outside of our own
4949 // waitForTransactionConfirm. because of this the progress bar loses
5050 // its progressiveness for metamask users.
51+
52+ // Per the web3 lib's Typescript declarations, sendTransaction
53+ // expects a Transaction nonce of type number to be passed in.
54+ // However, at runtime, Metamask throws an error indicating that
55+ // nonce should be a string.
56+ //@ts-ignore
5157 let receipt = await web3.eth.sendTransaction(metamaskFormattedTxn);
5258 txHash = receipt.transactionHash;
5359 }