I'm trying to transfer an erc-721 token between to different wallets. They're both connected to the ropsten network, and should have sufficient funds (0.08 and 0.1 eth) to make a transaction. However, I still get an error saying that
Something went wrong when submitting your transaction: Error: Returned error: insufficient funds for gas * price + value
I've looked at the other questions regarding this, but I didn't find much useful.
Code:
async function transfer(token, tokenId) {
const contract = new web3.eth.Contract(abi, token);
try {
const tx = {
from: publicKey,
to: token,
gas: 30000,
value: 0,
chain: "rinkeby",
baseChain: "rinkeby",
hardfork: "berlin",
data: contract.methods
.transferFrom(publicKey, toAddress, tokenId)
.encodeABI(),
};
const signed = await web3.eth.accounts.signTransaction(tx, privateKey);
const hash = await sendTx(signed);
try specify the gasPrice you want to use too,
like,
'gasPrice': web3.toWei('5','gwei')
your code:
async function transfer(token, tokenId) {
const contract = new web3.eth.Contract(abi, token);
try {
const tx = {
from: publicKey,
to: token,
gas: 30000,
gasPrice: web3.toWei('5','gwei'),
value: 0,
chain: "rinkeby",
baseChain: "rinkeby",
hardfork: "berlin",
data: contract.methods
.transferFrom(publicKey, toAddress, tokenId)
.encodeABI(),
};
const signed = await web3.eth.accounts.signTransaction(tx, privateKey);
const hash = await sendTx(signed);
ofcourse you would need to adjust the gasPrice according to the network
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.