[英]Web3: insufficient funds for gas * price + value
我正在尝试在不同的钱包之间转移一个 erc-721 令牌。 他们都连接到 ropsten 网络,并且应该有足够的资金(0.08 和 0.1 eth)来进行交易。 但是,我仍然收到一条错误消息
提交交易时出现问题:错误:返回错误:gas 资金不足 * 价格 + 价值
我已经查看了有关此的其他问题,但我发现没有多大用处。
代码:
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);
尝试指定您也想使用的gasPrice,
喜欢,
'gasPrice': web3.toWei('5','gwei')
你的代码:
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);
当然你需要根据网络调整gasPrice
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.