如果有更新,我可以按以下方式编写sendRawTransaction代码:
var rawTransaction = {"from":myAddress,
"gasPrice":web3js.toHex(2*1e9),
"gasLimit":web3js.toHex(920000),
"to":contractAddress,
"data":contract.addWalletEmail.getData(wallet, emailaddress),
"nonce":nounceHex}
var transaction = new Tx(rawTransaction);
transaction.sign(privateKey);
var serializedTx = transaction.serialize();
web3js.eth.sendRawTransaction('0x'+serializedTx.toString('hex'), function(err1, hash) {
});但是,当没有更新时,我们应该编写什么代码(例如通过getter检查变量)?我们还签txn等吗?
发布于 2018-10-25 17:57:31
由于您使用的是sendRawTransaction(),所以我假设您使用的是web3 v0.2x.x (而不是v1+)。
对于您的版本,您应该使用web3.eth.call(...)。
你不必在tx上签字。此外,你不会在只读电话上花费汽油(只要你对外打电话--而不是通过智能合同)。
因此,您的代码应该类似于: //abi是您的合同var ctr =newweb3.eth.Contract( abi,contractAddress)的abi;
web3.eth.call({"from":myAddress,
"to":contractAddress,
"data":ctr.methods.getData(wallet, emailaddress),
}, function(err1, hash) {
})https://ethereum.stackexchange.com/questions/61189
复制相似问题