簡體   English   中英

Web3:gas資金不足*價格+價值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM