it's been 2 days i am trying to figure out how to use web3.eth.accounts in my node application
I have Node and installed
"web3": "0.20.7",
"web3-eth-accounts": "^1.0.0-beta.47"
and trying to interact with Ethereum contract transaction (ERC20 transfer)
Now functions like are giving errors.
var account = web3.eth.accounts.privateKeyToAccount("0xc0370793a6d211618dbef5712380e744547e417e21fb295235ee2d4c94cd040");
So what is the proper way to work with web3.eth.accounts web3.eth.personal or web3.utils in Node on server side. Here is some code that i am trying to run. Here i just want to call ERC20 transfer function
Notice if i remove following then it works fine. Its because it used default account in Ganache-cli
var account = web3.eth.accounts.privateKeyToAccount("0xc0370793a6d211618dbef5712380e744547e417e21fb295235ee2d4c94cd040");
sendTokens: function(fromAddress, sendAddress, amountToSend, abi, contractAddress, web3Address) {
return new Promise(function(resolve, reject) {
var web3 = new Web3(new Web3.providers.HttpProvider(web3Address));
if(web3.isConnected()) {
var account = web3.eth.accounts.privateKeyToAccount("0xc0370793a6d211618dbef5712380e744547e417e21fb295235ee2d4c94cd040");
var contract = web3.eth.contract(abi);
var incubator = contract.at(contractAddress);
const transactionObject = {
from: account,
gas: 2000000,
gasPrice: 4
};
incubator.transfer.sendTransaction
( sendAddress, amountToSend, transactionObject, (error, result)=> {
resolve({"code":"1", data: result})
});
} else {
resolve({"code":"0", "message":"connection error"})
}
})
},
Shahzad Aslam
0 ·