Is it possible to force a transaction to be sent even if it will fail with useContractWrite? #2661
-
I am trying to force a transaction to be sent, so I can see where it's failing in a transaction inspector (like tenderly.co), so this is my current code: const {
data: dataOrder,
write: writeCreateOrder,
isLoading: loadingCreateOrderWrite,
} = useContractWrite({
// ...config,
...orderManager,
functionName: 'createOrder',
gas: 1_000_000n,
onSuccess: (data) => {
addRecentTransaction({
hash: data.hash,
description: 'Create Order',
});
toast.info('Creating Order');
setAmount('');
},
onError: () => {
toast.error('Error while Creating Order');
},
}); I was expecting if you give it a custom |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
In Ethereum, if a transaction encounters an error during execution, it will fail and any changes made during the execution will be reverted. Gas is used to pay for the computational resources needed to execute the transaction. If the gas limit provided is insufficient for the transaction to complete successfully, it will still fail even if you force the transaction to be sent. From your code snippet, it appears that you're setting a gas limit of 1,000,000 for the transaction. If this limit is insufficient for the transaction's execution, it will still fail regardless of whether you force it to be sent or not. |
Beta Was this translation helpful? Give feedback.
-
I believe the alternative is to pass useContractWrite({
mode: "prepared",
request: { // Your call that's actually not simulated & gas estimated.*
account: accountAddress,
chain: wagmiChain,
abi: ...
args: ...
gas: ... // Put some reasonable default here, otherwise it will be a huge limit (~28M)
}
}) |
Beta Was this translation helpful? Give feedback.
-
It's possible, but with viem, not wagmi: const walletClient = createWalletClient({
transport: custom(window.ethereum),
});
await walletClient.writeContract({
chain,
account,
address,
abi,
functionName,
args,
gas: 5000000n, // some reasonable number
}); |
Beta Was this translation helpful? Give feedback.
Hey, thanks for the heads up, but that wasn't my question, I just wanted to know if we can skip somehow the
eth_estimateGas
and just try to trigger the transaction regardless if it will fail or not, but setting thegas
does the job, thanks tho for the answer !