我试图从所有者帐户发送函数上的args,但得到返回错误。
我正在使用web3 1.0。
合同中的职能:
/**
* @dev Adds single address to whitelist.
* @param trusted Address to be added to the whitelist
*/
function addToWhiteList(address trusted) public onlyOwner {
require(!whitelist[trusted]);
whitelist[trusted] = true;
emit UserWhitelist(true);
}
index.html上的代码:
// Add user on whitelist
abc.methods.addToWhiteList("0x9DA80947ACf5Fc16299311EdAabc37fF7d201C95")
.send({ from: "0x61A44075419C4402f6DE631341d875Ece6A3922e" })
.on("receipt", function(receipt) {
console.log(receipt);
})
.on("error", function(error) {
console.error(error);
});
错误:Returned error: The method eth_sendTransaction does not exist/is not available
注意:我在脚本标记中添加了web3:
<script language="javascript" type="text/javascript" src="web3.min.js"></script>
也是如此。就像这样:
web3 = new Web3(new Web3.providers.WebsocketProvider("wss://ropsten.infura.io/ws"));
发布于 2018-05-17 05:58:12
我不知道这是否原因。但是,在发送事务之前,请尝试解锁帐户。发件人帐户需要解锁。通常,您会得到please unlock your account
错误。但也许这不允许你发送tx。示例代码如下所示:
custom_func.prototype.SENDCNK=function(from,to,password,amount){
return new Promise(function(fullfill,reject){
/* add basic checks like if user has sufficient balance , address are valid etc*/
web3.eth.personal.unlockAccount(from, password).then(function(result,e){
console.log("Account "+from+" unlocked successfully");
amount = parseFloat(amount);
amount = amount *decimalMultiplier;
cnkContract.methods.transfer(to ,amount).send({from:from})
.on('transactionHash',function(txHash){
console.log("Transaction hash : "+txHash);
fullfill(txHash);
}).catch(function(error){
console.log("Unable to send transaction. Error:"+error);
logger.error(error);
reject("Sending transaction on blockchain failed");
});
}).catch(function(error){
logger.error("Incorrect transaction password for account: "+from);
reject("Incorrect transaction password.");
});
});
}
https://ethereum.stackexchange.com/questions/48639
复制相似问题