I met the error when I learned to use the API of Web3.eth.sendSignedTransaction()
, here is my code and errors.
<script setup>
import {ref} from "vue";
import {Web3} from "web3";
var web3 = new Web3(Web3.givenProvider ||
"wss:[sepolia web]");
const address = ref("[The right sender address]")
const priKey = ref('[The right sender privateKey]')
const balance = ref(0)
web3.eth.getBalance(address.value).then((res) => {
balance.value = web3.utils.fromWei(res, 'ether');
})
const send = async () => {
const nonce = await web3.eth.getTransactionCount(address.value);
const txParams = {
nonce: web3.utils.toHex(nonce),
gasPrice: web3.utils.toHex(web3.utils.toWei('20', 'gwei')),
gasLimit: web3.utils.toHex(21000),
to: '[The right receiver address]',
value: web3.utils.toHex(web3.utils.toWei('0.01', 'ether')),
};
const signedTx = await web3.eth.accounts.signTransaction(txParams, priKey.value);
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
console.log('Transaction receipt:', receipt);
}
</script>
In the [] is the right infomations, and when I use the function send
and then get the errors:
get_transaction_error.js:67 Uncaught (in promise) TransactionRevertInstructionError: Transaction has been reverted by the EVM
at eval (get_transaction_error.js:67:15)
at Generator.next (<anonymous>)
at eval (get_transaction_error.js:47:67)
at new Promise (<anonymous>)
at __awaiter (get_transaction_error.js:29:10)
at getTransactionError (get_transaction_error.js:54:10)
at SendTxHelper.eval (send_tx_helper.js:116:101)
at Generator.next (<anonymous>)
at fulfilled (send_tx_helper.js:25:24)
My environment is over here:
Node.js -> 20.15.0
npm -> 10.7.0
vue/cli -> 5.0.0
vue -> 3.2.13
Web3.js -> 4.10.0
vant -> 4.9.1
Please help me to find out the error, I am a rookie in web3 🙁
I used ethereum-tx
to make the Transactions, but I failed.
Then I used the newest version @ethereumjs/tx
, but failed either….
I would be glad if you could tell me the usage of the @ethereumjs/tx
!