Ich versuche, die args on-Funktion vom Besitzerkonto zu senden, erhalte aber einen zurückgegebenen Fehler.
Ich verwende web3 1.0 .
Funktion im Vertrag:
/**
* @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);
}
Code auf 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);
});
FEHLER : Returned error: The method eth_sendTransaction does not exist/is not available
Hinweis: Ich füge web3 im script-Tag hinzu:
<script language="javascript" type="text/javascript" src="web3.min.js"></script>
und init. so was :
web3 = new Web3(new Web3.providers.WebsocketProvider("wss://ropsten.infura.io/ws"));
Ich bin mir nicht sicher, ob dies der Grund ist. Versuchen Sie jedoch, das Konto zu entsperren, bevor Sie die Transaktion senden. Das Absenderkonto muss entsperrt werden. Im Allgemeinen erhalten Sie please unlock your account
Fehler. Aber möglicherweise erlaubt Ihnen dies nicht, tx zu senden. Ein Beispielcode sieht so aus:
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.");
});
});
}
--rpcapi web3,eth,net,personal,db
. Wenn Sie dies nicht aktivieren, können Sie nicht auf persönliche Methoden zugreifen. Da Sie den Infura-Knoten verwenden, prüfen Sie, ob dieser aktiviert ist.
Prashant Prabhakar Singh
Chirag Maliwal
Prashant Prabhakar Singh
personal.unlock(owner)
Chirag Maliwal
Ismael
sendTransaction
Sie Ihre eigenen Transaktionen signieren und verwenden müssensendSignedTransaction
, oder verwenden Sie ein Plugin wie MetaMask, um Transaktionen zu signieren.