text 智能合约上的eth调用方法仅适用于web3

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 智能合约上的eth调用方法仅适用于web3相关的知识,希望对你有一定的参考价值。

const contract = new web3.eth.Contract(abiArray, contractAddr);
var func = contract.methods.myMethod('foo', 'bar')

var encodedFunc = func.encodeABI();

var tx = {
    from: ownerWallet,
    to: contractAddr,
    gas: web3.utils.toHex(1000000), //1m, also tried string '1000000'
    gasPrice: web3.utils.toHex(20000000000), //20gwei, also tried string '20000000000'
    data: encodedFunc
}

//might just be unnecessary three lines
const account = web3.eth.accounts.privateKeyToAccount(ownerPrivate)
console.log(account)
web3.eth.getBalance(ownerWallet).then(console.log)

const signed = await web3.eth.accounts.signTransaction(tx, ownerPrivate)
var trans = web3.eth.sendSignedTransaction(signed.rawTransaction)

以上是关于text 智能合约上的eth调用方法仅适用于web3的主要内容,如果未能解决你的问题,请参考以下文章