1

This question already has an answer here:

I have a local blockchain where I have deployed a contract. I want to interact with it sending multiple responses at the same time. For this propose, I cannot use Metamask to confirm each transaction. I need to create my own wallet and send the tx signed. I do not want to send a normal tx, I want to send a tx by calling a function in the contract.

For example:

pet-shop-tutorial. When you want to adopt a pet, you send a transaction from the .js file calling the adopt function with the account:

App.contracts.Adoption.deployed().then(function(instance) {
    adoptionInstance = instance;
    return adoptionInstance.adopt(petId, {from: account});
  }) 

How could I sign this kind of tx? Could anyone help me with this code?

UPDATED: I am using the following code to send a signed tx:

        var privateKey = "0xXX";
        var getdata = adoptionInstance.adopt(petId);
        var rawtx = {from: account, to: App.contracts.Adoption.address,  gas:2000000, data: getdata}
        var tx = new EthJS.Tx(rawtx);
        tx.sign(privateKey);

        var serializedtx = tx.serialize();

        web3.eth.sendSignedTransaction('0x' + serializedtx.toString('hex')).on('receipt', console.log);

I dont get any code error, but I have two problem cases:

1- If I keep MetaMask activated. I need to accept to send my tx from it and the tx is sent but never is confirmed.

2- If I desactivate Metamask. I get the following error in console: enter image description here

Could anyone help me with this?

marked as duplicate by Nulik, Richard Horrocks, Achala Dissanayake, Ismael, flygoing Sep 6 '18 at 14:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • It helps, but I need to send a signed tx and I am getting some problems. I update the question. – sapiensapiens Sep 5 '18 at 18:51