我已经编写了一个代码来部署带有两个变量的智能合约。还提供了一个帐户来签署交易,因此用户不必直接与合同进行交互。我已经在其他文件中制作了abi和合同的字节码,它也完整无缺。但是交易正在恢复。并没有执行。您能帮我吗。特定文件的代码是-
const Web3 = require('web3')
const contract = require('../contracts')
const network = {
rinkeby: "https://rinkeby.infura.io/v3/2cf3ec9bd42d4099b8620c2a6ee8c51a",
ropsten: "https://ropsten.infura.io/v3/2cf3ec9bd42d4099b8620c2a6ee8c51a",
quorum: "http://127.0.0.1:22000"
}
//34.213.150.192
const web3 = {
'rinkeby': new Web3(new Web3.providers.HttpProvider(network.rinkeby)),
'quorum': new Web3(new Web3.providers.HttpProvider(network.quorum)),
'ropsten': new Web3(new Web3.providers.HttpProvider(network.ropsten))
}
const keystore = {
rinkeby: {
address: "0x0b5E74f4cD6c78C1963D02db25a68e4f3d2CDe0E",
privateKey: "040C8FB1D157D0F7E3B6F29A41F9A90FC16D63D4273D221432BBCB7EB52862BB"
},
ropsten: {
address: "0x232D1038Ca6d21DF85F2109E6155E3f7c0Eea808",
privateKey: "dd3853d79745bd65a3a2691052e9fe27c39a314e45780b389e5ceb236d615f6c"
},
local: {
address: "0x9347ebf55cdb7d00b43f57d25f4e2c01b7c3a174",
privateKey: "273067fc6f762112438589da72b96e150ba1618cf01eee93975daab4076e49c0"
},
quorum: {
address: "0x41ad2bc63a2059f9b623533d87fe99887d794847",
privateKey: "e3b0c44298fc2000000000000000000000000000000000000000000000000000"
}
}
const AuthoxCoreContract = {
'rinkeby': new web3.rinkeby.eth.Contract(contract.abi, contract.address.rinkeby, {
from: keystore.rinkeby.address,
gas: 3000000,
}),
'ropsten': new web3.ropsten.eth.Contract(contract.abi, contract.address.ropsten, {
from: keystore.ropsten.address,
gas: 3000000,
}),
'quorum': new web3.quorum.eth.Contract(contract.abi, contract.address.quorum, {
from: keystore.quorum.address,
gas: 10000000,
})
}
var chainName = "ropsten"
let data = 'bytecode'
const Tx = require('ethereumjs-tx').Transaction
const privateKey = new Buffer.from(keystore[chainName].privateKey, 'hex')
web3[chainName].eth.getTransactionCount(keystore[chainName].address)
.then(nonce => {
console.log(nonce)
const rawTx = {
nonce: nonce,
gasPrice: chainName === 'quorum' ? 0 : 9000000000,
gasLimit: 4300000,
from: keystore[chainName].address,
data: data
}
const tx = new Tx(rawTx, {
chain: 'ropsten',
hardfork:
"homestead"
});
tx.sign(privateKey);
const serializedTx = tx.serialize()
web3[chainName].eth.sendSignedTransaction('0x' +
serializedTx.toString('hex'))
.on('transactionHash', function (hash) {
console.log(`hash: ${hash}`)
})
.on('receipt', function (receipt) {
console.log(`receipt: ${JSON.stringify(receipt)}`)
console.dir(receipt)
})
.on('confirmation', function (confirmationNumber, receipt) {
console.log(`confirmationNumber: ${confirmationNumber}, receipt: ${receipt} `)
//return resolve(receipt)
})
.on('error', function (error) {
console.error("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXx")
console.error(error)
//return reject(error)
})
})
输出的结果是-