I am using ethers js and want to send a transaction forcefully that might result in an error. Metamask allows me to do so, and so does remix, by hitting 'force send' - but when I do a contract call in my ethers code through a JSON RPC, it gives me an error saying 'transaction reverted: '
How can I force send a transaction programatically?
Solved - I was able to do this by overriding gas limit and gas price.
In order to do so, overrides object with preset param gasLimit should be passed as last parameter. See more at ethers docs
Reference to ethers library maintainer comment here
Related
I'm using ethers.js and trying to call for a method on a contract using
myContract.myMethod(amount, {"value": ethers.utils.parseEther((price * amount).toFixed(2))});
the toFixed() is not important here (it's only because calculations with multiply and float gives answers like 12.000000002 and it's not passing the validation from the contract
I'm using metamask for the user to interact with the contract, the problem is when I have balance 0, and I'm trying to call for myMethod I get an error: 'insufficient funds for gas * price + value' but I want it to be that metamask will open and show the transaction, and it will be the one that will show the 'insufficient fund' error without getting an error in my code (this is mostly for user-friendly from the metamask UI). I haven't found any answer about it in the ethers.js documentation and I saw some sites that implement this logic somehow (for example https://opensea.io/).
Example how it opens in opensea site:
Is it possible to do this through ethers.js or any other way?
Thank you.
Suppose an ethereum smart contract has external function "foo" whose logic has state-reverting exception require(1 == 0, 'error: you broke the simulation!');.
If ethereum-client A broadcasts transaction "txA" which is a function call on foo, how can ethereum-client B access the state-reverting message corresponding to "txA"?
edit: by "how can", I mean how can a developer practically enable ethereum-client B to access this data. i.e. Can you please point me in the direction of the correct (lower-level.. not webui) api/rpc call from a particular tool?
Clearly this is possible since block explorers provide such messages for failed transactions. I read through some of the source of etherscan, but their javascript is minimized and not easily readable.
Thanks in advance!
See this: https://ethereum.stackexchange.com/questions/39817/are-failed-transactions-included-in-the-blockchain
Failed transactions often are included in the chain.
What you sometimes see, if you're using e.g. MetaMask, is a popup saying "this transaction will fail" that happens before the transaction is sent to the chain. This is MetaMask trying to be helpful and prevent you wasting gas. But you can force send the transaction anyway, and you'll get a failed/reverted transaction posted on-chain (like this one for this Solidity source).
So to answer the original question, if TxA was posted on-chain, then client B will process it and get the revert message itself. If TxA was not posted on-chain, then there is no record of it.
When we call a solidity function via web3js, how does the code flows along with data formats during all the process?
For example, if I call a solidity function through web3js, how does it get executed. Can anyone explain the complete flow?
First of all, I recommend taking the time to read How does Ethereum work, anyway?
But for now, a short explanation
When you call a method on a contract through web3.js, the library
will encode your method call as data attribute on the transaction.
Here's a good explanation about ethereum transactions and data
attribute
The ethereum node your web3.js is connected to will receive your transactions and do some basic checks of nonce and balance
Once the basic checks pass, the node will broadcast the transaction to the rest of the network
When a network node receives a transaction with data attribute, it will execute the transaction using the Ethereum EVM. The outcome
of the transaction is modified state of the contract storage. More
about contract storage
The expectation is that the transaction will produce the same state change on every single node in the network. This is how
consensus is reached and the transaction (and the contract state
change) become part of the canonical chain (mined and not belonging
to an uncle block)
I am using testrpc and truffle to test my smart contract before deploying it to the real network.
In my contract, each node has to register in the contract by calling the function register, after that he can send or receive messages to/from contract( the blockchain )
The problem is, when an address ( let say account 1 from testrpc accounts) call the functions (send or receive ) the transaction doesn't occur and this message appears
VM Exception while processing transaction: invalid JUMP at
But when I use another unregistered account to call this function, it works.
Although no messages have been sent or received but no exceptions..
Any idea how I can solve this.
Thanks
Unless your using an old version of solc to compile your solidity the chance of this being an optimization problem is almost none.
Now, what does this mean then, it can happen when for example you run a modifier and it doesn't work. or if you try to call a function you are not allowed to and it throws. For example, it happens a lot after an ICO finishes and you try to use a function that can't be used anymore due to a date constraint it returns an Invalid Jump
I can't see your code but I think you might have reversed your if condition in your modifier and now it returns true if the user is not registered.
I am wandering how to set the custom account to execute transaction? For example in truffle console i have something like
Hello.deployed().then(function(){h = instance})
, and then
h.exetuceTransaction()
will burn gas from the accounts[0] by default. How can I specify the account from which I want to send this transaction (for example accouts[1])?
You just have to specify the from parameter when calling executeTransaction({"from" : "0x..." }) check The doc