0

Good morning,

I need to known how call contract method in javascript from specific address(and relative private key) without the check of Metamask. I explain better.

This is an example of js code, it works but every time i call the method, Metamask ask the check and i need to iterate this function.

func: function() {

  App.contracts.Bidder.deployed().then(function(instance) {
    return instance.addBid(1, 10, 1, { from: address });

So I ask if there is a way to do this automatically inserting the private key in the code like the address.

This is for a local blockchain with truffle and ganache.

Thanks.

  • 1
    Yes, if you sign your transaction and send it with eth.sendRawTransaction, there's an example in the documentation how to sign it using ethereumjs-tx and your private key. – Ismael Feb 3 at 7:03
  • Thanks, I have 2 questions: how can I sing and call a specific method as raw transaction? And what is the role of ethereumjs-tx here? Thank you very much. – Chaos Feb 4 at 11:25
  • To sign a transaction you need to RLP encode it, ethereumjs-tx will properly RLP encode a transaction and has a function to sign it. With web3 v1 you have a function encodeABI that you can use to format a function call in a message suitable for the data field of a transaction. – Ismael Feb 4 at 21:18

Your Answer

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

Browse other questions tagged or ask your own question.