MetaMask Web3对象不支持没有回调参数的eth_sendTransaction之类的同步方法

问题描述 投票:0回答:1

我在名为'gameDeposit'的智能合约中有一个应付款功能,用户需要存入eth才能参与游戏,但是当我使用web3 javascript API调用它时它给了我未捕获的错误

inpage.js:1 Uncaught (in promise) Error: The MetaMask Web3 object does not support synchronous methods like eth_sendTransaction without a callback parameter
        const Abi = [{ABI}];
        const contractAbi = web3.eth.contract(Abi);
        const myContract = contractAbi.at("0x3....");
        const amountEth = '0.01';
        console.log(myContract);
        const gameID = '10';
        myContract.gameDeposit(gameID).send({
            from: web3.eth.accounts[0],
            value: web3.toWei(amountEth, 'ether')
        },(error , result) => {
            if(!error)
                console.log(result);
            else
                console.error(error)
        })
    })
javascript ethereum smartcontracts web3
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.