3

Under Ganache, I created some APIs with nodejs to managing a Smart Contract. One API is for the creation of new accounts with

newAccount = web3.eth.accounts.create(web3.utils.randomHex(32));

Then, with another API, when I try to access a function of the Smart Contract with

contractInstance.methods.myFunction(param1, param2, param3).send({
from: newAccount.address,
gas: 4600000
}).on('transactionHash', function(hash){
console.log(hash);
}).on('error', console.error);
});

the transaction fails with the error

sender account not recognized

Where am I wrong?

Thank you

  • did my answer worked for you?. I am curious. – Jaime Jun 19 '18 at 15:32
3

Probably after creating the account in the way you do, your new address is not returned when you do web3.eth.getAccounts() because this creates an account that is not associated with your node.

Use instead web3.eth.personal.newAccount(password, [callback])

Hope this helps.

  • is there a way to specify our own public and private key while using web3.eth.personal.newAccount(password, [callback]) ? – Zeeshan Ahmad Khalil Nov 1 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.