您好,我尝试通过lambda函数部署智能合约,很遗憾,我在sendSignedTransaction()函数上感到以下错误,有人可以告诉我这里有什么问题吗?。
Error: Returned error: invalid sender
var blockchain = process.env.BLOCKCHAIN_HOST
var web3 = new Web3(new Web3.providers.HttpProvider('http://' + blockchain + ':8545'))
// Get the Bytecode
var byteCode = compiledCode.contracts[':auction'].bytecode
const contractOwner = '0x34db0A1FDGDCCDDDDXCX191e703Bf0182E0baE3'
const privateKey = '0x403cf58c6a36eee43ac8467bec2c9d6546454461debffb4acff277548ef3'
const tx = {
chainId: await web3.eth.net.getId(),
nonce: await web3.utils.toHex(await web3.eth.getTransactionCount(contractOwner)),
gas: 4612388,
from: contractOwner,
data: byteCode
}
console.log(tx)
const signedTx = await web3.eth.accounts.signTransaction(tx, privateKey)
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction)
console.log(receipt.contractAddress)
答案 0 :(得分:2)
这是chainId
最常见的问题。确保已正确声明chainId
文件config
部分中的genesis.json
,如下所示:
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
}
此外,请确保await web3.eth.net.getId()
返回的值与您已配置的值匹配。