From 1ec6a6028f6df6a6e35811e235f765c62a2eaccb Mon Sep 17 00:00:00 2001 From: Sebastian Pape <0xneo11@gmail.com> Date: Thu, 14 Dec 2023 15:30:06 +0100 Subject: [PATCH] catch estimates --- dist/esm/index.evm.js | 50 ++++++++++++++-------- dist/esm/index.js | 50 ++++++++++++++-------- dist/umd/index.evm.js | 50 ++++++++++++++-------- dist/umd/index.js | 50 ++++++++++++++-------- src/wallets/WalletConnectV1/transaction.js | 16 ++++--- src/wallets/WalletConnectV2/transaction.js | 17 +++++--- src/wallets/WindowEthereum/transaction.js | 15 ++++--- 7 files changed, 164 insertions(+), 84 deletions(-) diff --git a/dist/esm/index.evm.js b/dist/esm/index.evm.js index 7ac4620..0b2edf4 100644 --- a/dist/esm/index.evm.js +++ b/dist/esm/index.evm.js @@ -243,17 +243,20 @@ const submitContractInteraction$3 = async ({ transaction, signer, provider })=>{ let contract = new ethers.Contract(transaction.to, transaction.api, provider); let contractArguments = transaction.getContractArguments({ contract }); let method = contract.connect(signer)[transaction.getMethodNameWithSignature()]; - let gas = await estimate(transaction); - gas = gas.add(gas.div(10)); + let gas; + try { + gas = await estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e) {} if(contractArguments) { - return method(...contractArguments, { + return await method(...contractArguments, { value: Transaction.bigNumberify(transaction.value, transaction.blockchain), - gasLimit: gas ? gas.toHexString() : undefined + gasLimit: _optionalChain$j([gas, 'optionalAccess', _7 => _7.toHexString, 'call', _8 => _8()]) }) } else { - return method({ + return await method({ value: Transaction.bigNumberify(transaction.value, transaction.blockchain), - gasLimit: gas ? gas.toHexString() : undefined + gasLimit: _optionalChain$j([gas, 'optionalAccess', _9 => _9.toHexString, 'call', _10 => _10()]) }) } }; @@ -875,17 +878,20 @@ const submitContractInteraction$2 = async ({ transaction, wallet })=>{ } else { gasPrice = gasPrice.toHexString(); } - let gas = await estimate(transaction); + let gas; + try { + gas = await estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e2) {} const data = await transaction.getData(); const value = transaction.value ? ethers.utils.hexlify(ethers.BigNumber.from(transaction.value)) : undefined; const nonce = ethers.utils.hexlify(transaction.nonce); - gas = gas.add(gas.div(10)); return wallet.connector.sendTransaction({ from: transaction.from, to: transaction.to, value, data, - gas: gas.toHexString(), + gas: _optionalChain$5([gas, 'optionalAccess', _10 => _10.toHexString, 'call', _11 => _11()]), gasPrice, nonce, }) @@ -894,12 +900,15 @@ const submitContractInteraction$2 = async ({ transaction, wallet })=>{ const submitSimpleTransfer$2 = async ({ transaction, wallet })=>{ const provider = await getProvider(transaction.blockchain); let gasPrice = await provider.getGasPrice(); - if(_optionalChain$5([wallet, 'access', _10 => _10.session, 'optionalAccess', _11 => _11.peerMeta, 'optionalAccess', _12 => _12.name]) === 'Uniswap Wallet') { + if(_optionalChain$5([wallet, 'access', _12 => _12.session, 'optionalAccess', _13 => _13.peerMeta, 'optionalAccess', _14 => _14.name]) === 'Uniswap Wallet') { gasPrice = undefined; } else { gasPrice = gasPrice.toHexString(); } - const gas = await estimate(transaction); + try { + gas = await estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e3) {} const value = ethers.utils.hexlify(ethers.BigNumber.from(transaction.value)); const nonce = ethers.utils.hexlify(transaction.nonce); return wallet.connector.sendTransaction({ @@ -907,7 +916,7 @@ const submitSimpleTransfer$2 = async ({ transaction, wallet })=>{ to: transaction.to, value, data: '0x', - gas: gas.toHexString(), + gas: _optionalChain$5([gas, 'optionalAccess', _15 => _15.toHexString, 'call', _16 => _16()]), gasPrice, nonce, }) @@ -1326,8 +1335,11 @@ const submit$1 = ({ transaction, wallet }) => { const submitContractInteraction$1 = async ({ transaction, wallet })=>{ const provider = await getProvider(transaction.blockchain); const blockchain = Blockchains[transaction.blockchain]; - let gas = await estimate(transaction); - gas = gas.add(gas.div(10)); + let gas; + try { + gas = await estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e2) {} const gasPrice = await provider.getGasPrice(); return wallet.signClient.request({ topic: wallet.session.topic, @@ -1339,7 +1351,7 @@ const submitContractInteraction$1 = async ({ transaction, wallet })=>{ to: transaction.to, value: transaction.value ? ethers.BigNumber.from(transaction.value.toString()).toHexString() : undefined, data: await transaction.getData(), - gas: gas.toHexString(), + gas: _optionalChain$3([gas, 'optionalAccess', _10 => _10.toHexString, 'call', _11 => _11()]), gasPrice: gasPrice.toHexString(), nonce: transaction.nonce, }] @@ -1350,7 +1362,11 @@ const submitContractInteraction$1 = async ({ transaction, wallet })=>{ const submitSimpleTransfer$1 = async ({ transaction, wallet })=>{ const provider = await getProvider(transaction.blockchain); let blockchain = Blockchains[transaction.blockchain]; - const gas = await estimate(transaction); + let gas; + try { + gas = await estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e3) {} const gasPrice = await provider.getGasPrice(); return wallet.signClient.request({ topic: wallet.session.topic, @@ -1361,7 +1377,7 @@ const submitSimpleTransfer$1 = async ({ transaction, wallet })=>{ from: transaction.from, to: transaction.to, value: transaction.value ? ethers.BigNumber.from(transaction.value.toString()).toHexString() : undefined, - gas: gas.toHexString(), + gas: _optionalChain$3([gas, 'optionalAccess', _12 => _12.toHexString, 'call', _13 => _13()]), gasPrice: gasPrice.toHexString(), nonce: transaction.nonce }] diff --git a/dist/esm/index.js b/dist/esm/index.js index 531b68d..dd57e06 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -510,17 +510,20 @@ const submitContractInteraction$3 = async ({ transaction, signer, provider })=>{ let contract = new ethers.Contract(transaction.to, transaction.api, provider); let contractArguments = transaction.getContractArguments({ contract }); let method = contract.connect(signer)[transaction.getMethodNameWithSignature()]; - let gas = await estimate(transaction); - gas = gas.add(gas.div(10)); + let gas; + try { + gas = await estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e) {} if(contractArguments) { - return method(...contractArguments, { + return await method(...contractArguments, { value: Transaction.bigNumberify(transaction.value, transaction.blockchain), - gasLimit: gas ? gas.toHexString() : undefined + gasLimit: _optionalChain$p([gas, 'optionalAccess', _7 => _7.toHexString, 'call', _8 => _8()]) }) } else { - return method({ + return await method({ value: Transaction.bigNumberify(transaction.value, transaction.blockchain), - gasLimit: gas ? gas.toHexString() : undefined + gasLimit: _optionalChain$p([gas, 'optionalAccess', _9 => _9.toHexString, 'call', _10 => _10()]) }) } }; @@ -1413,17 +1416,20 @@ const submitContractInteraction$2 = async ({ transaction, wallet })=>{ } else { gasPrice = gasPrice.toHexString(); } - let gas = await estimate(transaction); + let gas; + try { + gas = await estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e2) {} const data = await transaction.getData(); const value = transaction.value ? ethers.utils.hexlify(ethers.BigNumber.from(transaction.value)) : undefined; const nonce = ethers.utils.hexlify(transaction.nonce); - gas = gas.add(gas.div(10)); return wallet.connector.sendTransaction({ from: transaction.from, to: transaction.to, value, data, - gas: gas.toHexString(), + gas: _optionalChain$5([gas, 'optionalAccess', _10 => _10.toHexString, 'call', _11 => _11()]), gasPrice, nonce, }) @@ -1432,12 +1438,15 @@ const submitContractInteraction$2 = async ({ transaction, wallet })=>{ const submitSimpleTransfer$2 = async ({ transaction, wallet })=>{ const provider = await getProvider(transaction.blockchain); let gasPrice = await provider.getGasPrice(); - if(_optionalChain$5([wallet, 'access', _10 => _10.session, 'optionalAccess', _11 => _11.peerMeta, 'optionalAccess', _12 => _12.name]) === 'Uniswap Wallet') { + if(_optionalChain$5([wallet, 'access', _12 => _12.session, 'optionalAccess', _13 => _13.peerMeta, 'optionalAccess', _14 => _14.name]) === 'Uniswap Wallet') { gasPrice = undefined; } else { gasPrice = gasPrice.toHexString(); } - const gas = await estimate(transaction); + try { + gas = await estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e3) {} const value = ethers.utils.hexlify(ethers.BigNumber.from(transaction.value)); const nonce = ethers.utils.hexlify(transaction.nonce); return wallet.connector.sendTransaction({ @@ -1445,7 +1454,7 @@ const submitSimpleTransfer$2 = async ({ transaction, wallet })=>{ to: transaction.to, value, data: '0x', - gas: gas.toHexString(), + gas: _optionalChain$5([gas, 'optionalAccess', _15 => _15.toHexString, 'call', _16 => _16()]), gasPrice, nonce, }) @@ -1864,8 +1873,11 @@ const submit$1 = ({ transaction, wallet }) => { const submitContractInteraction$1 = async ({ transaction, wallet })=>{ const provider = await getProvider(transaction.blockchain); const blockchain = Blockchains[transaction.blockchain]; - let gas = await estimate(transaction); - gas = gas.add(gas.div(10)); + let gas; + try { + gas = await estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e2) {} const gasPrice = await provider.getGasPrice(); return wallet.signClient.request({ topic: wallet.session.topic, @@ -1877,7 +1889,7 @@ const submitContractInteraction$1 = async ({ transaction, wallet })=>{ to: transaction.to, value: transaction.value ? ethers.BigNumber.from(transaction.value.toString()).toHexString() : undefined, data: await transaction.getData(), - gas: gas.toHexString(), + gas: _optionalChain$3([gas, 'optionalAccess', _10 => _10.toHexString, 'call', _11 => _11()]), gasPrice: gasPrice.toHexString(), nonce: transaction.nonce, }] @@ -1888,7 +1900,11 @@ const submitContractInteraction$1 = async ({ transaction, wallet })=>{ const submitSimpleTransfer$1 = async ({ transaction, wallet })=>{ const provider = await getProvider(transaction.blockchain); let blockchain = Blockchains[transaction.blockchain]; - const gas = await estimate(transaction); + let gas; + try { + gas = await estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e3) {} const gasPrice = await provider.getGasPrice(); return wallet.signClient.request({ topic: wallet.session.topic, @@ -1899,7 +1915,7 @@ const submitSimpleTransfer$1 = async ({ transaction, wallet })=>{ from: transaction.from, to: transaction.to, value: transaction.value ? ethers.BigNumber.from(transaction.value.toString()).toHexString() : undefined, - gas: gas.toHexString(), + gas: _optionalChain$3([gas, 'optionalAccess', _12 => _12.toHexString, 'call', _13 => _13()]), gasPrice: gasPrice.toHexString(), nonce: transaction.nonce }] diff --git a/dist/umd/index.evm.js b/dist/umd/index.evm.js index aaac76f..962b2ec 100644 --- a/dist/umd/index.evm.js +++ b/dist/umd/index.evm.js @@ -246,17 +246,20 @@ let contract = new ethers.ethers.Contract(transaction.to, transaction.api, provider); let contractArguments = transaction.getContractArguments({ contract }); let method = contract.connect(signer)[transaction.getMethodNameWithSignature()]; - let gas = await web3ClientEvm.estimate(transaction); - gas = gas.add(gas.div(10)); + let gas; + try { + gas = await web3ClientEvm.estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e) {} if(contractArguments) { - return method(...contractArguments, { + return await method(...contractArguments, { value: Transaction.bigNumberify(transaction.value, transaction.blockchain), - gasLimit: gas ? gas.toHexString() : undefined + gasLimit: _optionalChain$j([gas, 'optionalAccess', _7 => _7.toHexString, 'call', _8 => _8()]) }) } else { - return method({ + return await method({ value: Transaction.bigNumberify(transaction.value, transaction.blockchain), - gasLimit: gas ? gas.toHexString() : undefined + gasLimit: _optionalChain$j([gas, 'optionalAccess', _9 => _9.toHexString, 'call', _10 => _10()]) }) } }; @@ -878,17 +881,20 @@ } else { gasPrice = gasPrice.toHexString(); } - let gas = await web3ClientEvm.estimate(transaction); + let gas; + try { + gas = await web3ClientEvm.estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e2) {} const data = await transaction.getData(); const value = transaction.value ? ethers.ethers.utils.hexlify(ethers.ethers.BigNumber.from(transaction.value)) : undefined; const nonce = ethers.ethers.utils.hexlify(transaction.nonce); - gas = gas.add(gas.div(10)); return wallet.connector.sendTransaction({ from: transaction.from, to: transaction.to, value, data, - gas: gas.toHexString(), + gas: _optionalChain$5([gas, 'optionalAccess', _10 => _10.toHexString, 'call', _11 => _11()]), gasPrice, nonce, }) @@ -897,12 +903,15 @@ const submitSimpleTransfer$2 = async ({ transaction, wallet })=>{ const provider = await web3ClientEvm.getProvider(transaction.blockchain); let gasPrice = await provider.getGasPrice(); - if(_optionalChain$5([wallet, 'access', _10 => _10.session, 'optionalAccess', _11 => _11.peerMeta, 'optionalAccess', _12 => _12.name]) === 'Uniswap Wallet') { + if(_optionalChain$5([wallet, 'access', _12 => _12.session, 'optionalAccess', _13 => _13.peerMeta, 'optionalAccess', _14 => _14.name]) === 'Uniswap Wallet') { gasPrice = undefined; } else { gasPrice = gasPrice.toHexString(); } - const gas = await web3ClientEvm.estimate(transaction); + try { + gas = await web3ClientEvm.estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e3) {} const value = ethers.ethers.utils.hexlify(ethers.ethers.BigNumber.from(transaction.value)); const nonce = ethers.ethers.utils.hexlify(transaction.nonce); return wallet.connector.sendTransaction({ @@ -910,7 +919,7 @@ to: transaction.to, value, data: '0x', - gas: gas.toHexString(), + gas: _optionalChain$5([gas, 'optionalAccess', _15 => _15.toHexString, 'call', _16 => _16()]), gasPrice, nonce, }) @@ -1329,8 +1338,11 @@ const submitContractInteraction$1 = async ({ transaction, wallet })=>{ const provider = await web3ClientEvm.getProvider(transaction.blockchain); const blockchain = Blockchains__default['default'][transaction.blockchain]; - let gas = await web3ClientEvm.estimate(transaction); - gas = gas.add(gas.div(10)); + let gas; + try { + gas = await web3ClientEvm.estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e2) {} const gasPrice = await provider.getGasPrice(); return wallet.signClient.request({ topic: wallet.session.topic, @@ -1342,7 +1354,7 @@ to: transaction.to, value: transaction.value ? ethers.ethers.BigNumber.from(transaction.value.toString()).toHexString() : undefined, data: await transaction.getData(), - gas: gas.toHexString(), + gas: _optionalChain$3([gas, 'optionalAccess', _10 => _10.toHexString, 'call', _11 => _11()]), gasPrice: gasPrice.toHexString(), nonce: transaction.nonce, }] @@ -1353,7 +1365,11 @@ const submitSimpleTransfer$1 = async ({ transaction, wallet })=>{ const provider = await web3ClientEvm.getProvider(transaction.blockchain); let blockchain = Blockchains__default['default'][transaction.blockchain]; - const gas = await web3ClientEvm.estimate(transaction); + let gas; + try { + gas = await web3ClientEvm.estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e3) {} const gasPrice = await provider.getGasPrice(); return wallet.signClient.request({ topic: wallet.session.topic, @@ -1364,7 +1380,7 @@ from: transaction.from, to: transaction.to, value: transaction.value ? ethers.ethers.BigNumber.from(transaction.value.toString()).toHexString() : undefined, - gas: gas.toHexString(), + gas: _optionalChain$3([gas, 'optionalAccess', _12 => _12.toHexString, 'call', _13 => _13()]), gasPrice: gasPrice.toHexString(), nonce: transaction.nonce }] diff --git a/dist/umd/index.js b/dist/umd/index.js index 598f5e0..a001ef0 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -512,17 +512,20 @@ let contract = new ethers.ethers.Contract(transaction.to, transaction.api, provider); let contractArguments = transaction.getContractArguments({ contract }); let method = contract.connect(signer)[transaction.getMethodNameWithSignature()]; - let gas = await web3Client.estimate(transaction); - gas = gas.add(gas.div(10)); + let gas; + try { + gas = await web3Client.estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e) {} if(contractArguments) { - return method(...contractArguments, { + return await method(...contractArguments, { value: Transaction.bigNumberify(transaction.value, transaction.blockchain), - gasLimit: gas ? gas.toHexString() : undefined + gasLimit: _optionalChain$p([gas, 'optionalAccess', _7 => _7.toHexString, 'call', _8 => _8()]) }) } else { - return method({ + return await method({ value: Transaction.bigNumberify(transaction.value, transaction.blockchain), - gasLimit: gas ? gas.toHexString() : undefined + gasLimit: _optionalChain$p([gas, 'optionalAccess', _9 => _9.toHexString, 'call', _10 => _10()]) }) } }; @@ -1415,17 +1418,20 @@ } else { gasPrice = gasPrice.toHexString(); } - let gas = await web3Client.estimate(transaction); + let gas; + try { + gas = await web3Client.estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e2) {} const data = await transaction.getData(); const value = transaction.value ? ethers.ethers.utils.hexlify(ethers.ethers.BigNumber.from(transaction.value)) : undefined; const nonce = ethers.ethers.utils.hexlify(transaction.nonce); - gas = gas.add(gas.div(10)); return wallet.connector.sendTransaction({ from: transaction.from, to: transaction.to, value, data, - gas: gas.toHexString(), + gas: _optionalChain$5([gas, 'optionalAccess', _10 => _10.toHexString, 'call', _11 => _11()]), gasPrice, nonce, }) @@ -1434,12 +1440,15 @@ const submitSimpleTransfer$2 = async ({ transaction, wallet })=>{ const provider = await web3Client.getProvider(transaction.blockchain); let gasPrice = await provider.getGasPrice(); - if(_optionalChain$5([wallet, 'access', _10 => _10.session, 'optionalAccess', _11 => _11.peerMeta, 'optionalAccess', _12 => _12.name]) === 'Uniswap Wallet') { + if(_optionalChain$5([wallet, 'access', _12 => _12.session, 'optionalAccess', _13 => _13.peerMeta, 'optionalAccess', _14 => _14.name]) === 'Uniswap Wallet') { gasPrice = undefined; } else { gasPrice = gasPrice.toHexString(); } - const gas = await web3Client.estimate(transaction); + try { + gas = await web3Client.estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e3) {} const value = ethers.ethers.utils.hexlify(ethers.ethers.BigNumber.from(transaction.value)); const nonce = ethers.ethers.utils.hexlify(transaction.nonce); return wallet.connector.sendTransaction({ @@ -1447,7 +1456,7 @@ to: transaction.to, value, data: '0x', - gas: gas.toHexString(), + gas: _optionalChain$5([gas, 'optionalAccess', _15 => _15.toHexString, 'call', _16 => _16()]), gasPrice, nonce, }) @@ -1866,8 +1875,11 @@ const submitContractInteraction$1 = async ({ transaction, wallet })=>{ const provider = await web3Client.getProvider(transaction.blockchain); const blockchain = Blockchains__default['default'][transaction.blockchain]; - let gas = await web3Client.estimate(transaction); - gas = gas.add(gas.div(10)); + let gas; + try { + gas = await web3Client.estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e2) {} const gasPrice = await provider.getGasPrice(); return wallet.signClient.request({ topic: wallet.session.topic, @@ -1879,7 +1891,7 @@ to: transaction.to, value: transaction.value ? ethers.ethers.BigNumber.from(transaction.value.toString()).toHexString() : undefined, data: await transaction.getData(), - gas: gas.toHexString(), + gas: _optionalChain$3([gas, 'optionalAccess', _10 => _10.toHexString, 'call', _11 => _11()]), gasPrice: gasPrice.toHexString(), nonce: transaction.nonce, }] @@ -1890,7 +1902,11 @@ const submitSimpleTransfer$1 = async ({ transaction, wallet })=>{ const provider = await web3Client.getProvider(transaction.blockchain); let blockchain = Blockchains__default['default'][transaction.blockchain]; - const gas = await web3Client.estimate(transaction); + let gas; + try { + gas = await web3Client.estimate(transaction); + gas = gas.add(gas.div(10)); + } catch (e3) {} const gasPrice = await provider.getGasPrice(); return wallet.signClient.request({ topic: wallet.session.topic, @@ -1901,7 +1917,7 @@ from: transaction.from, to: transaction.to, value: transaction.value ? ethers.ethers.BigNumber.from(transaction.value.toString()).toHexString() : undefined, - gas: gas.toHexString(), + gas: _optionalChain$3([gas, 'optionalAccess', _12 => _12.toHexString, 'call', _13 => _13()]), gasPrice: gasPrice.toHexString(), nonce: transaction.nonce }] diff --git a/src/wallets/WalletConnectV1/transaction.js b/src/wallets/WalletConnectV1/transaction.js index a91e624..54e871c 100644 --- a/src/wallets/WalletConnectV1/transaction.js +++ b/src/wallets/WalletConnectV1/transaction.js @@ -135,17 +135,20 @@ const submitContractInteraction = async ({ transaction, wallet })=>{ } else { gasPrice = gasPrice.toHexString() } - let gas = await estimate(transaction) + let gas + try { + gas = await estimate(transaction) + gas = gas.add(gas.div(10)) + } catch {} const data = await transaction.getData() const value = transaction.value ? ethers.utils.hexlify(ethers.BigNumber.from(transaction.value)) : undefined const nonce = ethers.utils.hexlify(transaction.nonce) - gas = gas.add(gas.div(10)) return wallet.connector.sendTransaction({ from: transaction.from, to: transaction.to, value, data, - gas: gas.toHexString(), + gas: gas?.toHexString(), gasPrice, nonce, }) @@ -159,7 +162,10 @@ const submitSimpleTransfer = async ({ transaction, wallet })=>{ } else { gasPrice = gasPrice.toHexString() } - const gas = await estimate(transaction) + try { + gas = await estimate(transaction) + gas = gas.add(gas.div(10)) + } catch {} const value = ethers.utils.hexlify(ethers.BigNumber.from(transaction.value)) const nonce = ethers.utils.hexlify(transaction.nonce) return wallet.connector.sendTransaction({ @@ -167,7 +173,7 @@ const submitSimpleTransfer = async ({ transaction, wallet })=>{ to: transaction.to, value, data: '0x', - gas: gas.toHexString(), + gas: gas?.toHexString(), gasPrice, nonce, }) diff --git a/src/wallets/WalletConnectV2/transaction.js b/src/wallets/WalletConnectV2/transaction.js index 1a31cdd..187ce5a 100644 --- a/src/wallets/WalletConnectV2/transaction.js +++ b/src/wallets/WalletConnectV2/transaction.js @@ -139,8 +139,11 @@ const submit = ({ transaction, wallet }) => { const submitContractInteraction = async ({ transaction, wallet })=>{ const provider = await getProvider(transaction.blockchain) const blockchain = Blockchains[transaction.blockchain] - let gas = await estimate(transaction) - gas = gas.add(gas.div(10)) + let gas + try { + gas = await estimate(transaction) + gas = gas.add(gas.div(10)) + } catch {} const gasPrice = await provider.getGasPrice() return wallet.signClient.request({ topic: wallet.session.topic, @@ -152,7 +155,7 @@ const submitContractInteraction = async ({ transaction, wallet })=>{ to: transaction.to, value: transaction.value ? ethers.BigNumber.from(transaction.value.toString()).toHexString() : undefined, data: await transaction.getData(), - gas: gas.toHexString(), + gas: gas?.toHexString(), gasPrice: gasPrice.toHexString(), nonce: transaction.nonce, }] @@ -163,7 +166,11 @@ const submitContractInteraction = async ({ transaction, wallet })=>{ const submitSimpleTransfer = async ({ transaction, wallet })=>{ const provider = await getProvider(transaction.blockchain) let blockchain = Blockchains[transaction.blockchain] - const gas = await estimate(transaction) + let gas + try { + gas = await estimate(transaction) + gas = gas.add(gas.div(10)) + } catch {} const gasPrice = await provider.getGasPrice() return wallet.signClient.request({ topic: wallet.session.topic, @@ -174,7 +181,7 @@ const submitSimpleTransfer = async ({ transaction, wallet })=>{ from: transaction.from, to: transaction.to, value: transaction.value ? ethers.BigNumber.from(transaction.value.toString()).toHexString() : undefined, - gas: gas.toHexString(), + gas: gas?.toHexString(), gasPrice: gasPrice.toHexString(), nonce: transaction.nonce }] diff --git a/src/wallets/WindowEthereum/transaction.js b/src/wallets/WindowEthereum/transaction.js index 40361c2..a859729 100644 --- a/src/wallets/WindowEthereum/transaction.js +++ b/src/wallets/WindowEthereum/transaction.js @@ -110,17 +110,20 @@ const submitContractInteraction = async ({ transaction, signer, provider })=>{ let contract = new ethers.Contract(transaction.to, transaction.api, provider) let contractArguments = transaction.getContractArguments({ contract }) let method = contract.connect(signer)[transaction.getMethodNameWithSignature()] - let gas = await estimate(transaction) - gas = gas.add(gas.div(10)) + let gas + try { + gas = await estimate(transaction) + gas = gas.add(gas.div(10)) + } catch {} if(contractArguments) { - return method(...contractArguments, { + return await method(...contractArguments, { value: Transaction.bigNumberify(transaction.value, transaction.blockchain), - gasLimit: gas ? gas.toHexString() : undefined + gasLimit: gas?.toHexString() }) } else { - return method({ + return await method({ value: Transaction.bigNumberify(transaction.value, transaction.blockchain), - gasLimit: gas ? gas.toHexString() : undefined + gasLimit: gas?.toHexString() }) } }