1

I run ganache, truffle and metmask. If I run the code below I get an error on the this.web3.eth.sendSignedTransaction() function:

EDIT: changed my code to the following.. Error remained the same though.

    const encoded_tx = this.contract.methods.createCountry("NL", 100, 100, 100000000, this.account).encodeABI();
    const nonce = await this.web3.eth.getBlockTransactionCount(this.account);
    const rawTx = {
        nonce: this.utils.toHex(nonce), 
        gasLimit: this.utils.toHex(3000000),
        gasPrice: this.utils.toHex(this.utils.toWei('20', 'gwei')),
        data: encoded_tx,
        from: this.account,
        to: this.contractAddress
    };

    let tx = new Tx(rawTx);
    tx.sign(this.pvtKey);

    let serializedTx = tx.serialize();
    this.web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
    .on('receipt', console.log);

The error is the following:

index.js:2178 Error: Returned error: {"id":6,"jsonrpc":"2.0","error":{"code":-32603}}
at Object.ErrorResponse (errors.js:29)

I have absolutely no idea where to look anymore and feel like I've tried everything, might it have anything to do with the fact that I'm connected to metamask? When I try to send this transaction through metamask with eth.method.send() the transaction does not give an error and behaves as expected.

  • One way to investigate this is to open Ganache Core source code and search for -32603 (or more precisely, the hexadecimal representation of 2^32 - 32603). – goodvibration May 18 '18 at 8:48
  • Thanks for your quick response but this does not seem to get any hits: github.com/trufflesuite/ganache-core/… – jasper May 18 '18 at 8:53
  • 1
    After doing some research I found out that the error code only means that it's an internal json-rpc error, which isn't helpful at all. – jasper May 18 '18 at 9:05
  • It is. I don't use ganache, but I assume you have to open specific librairies no? Check if RPC allows the connection to use the librairies you use (web3, web3.eth, etc) – Florian Castelain May 18 '18 at 10:56
  • I think Ganache might not support sendSignedTransaction yet.. I've created an issue – jasper May 18 '18 at 12:27
2

To get the nonce you have to call web3.eth.getTransactionCount, and not getBlockTransactionCount.

  • getTransactionCount

    Get the numbers of transactions sent from this address.

  • getBlockTransactionCount

    Returns the number of transaction in a given block.

To debug interactions with ganache you can start with ganache-cli --verbose it will show the interactions between the client an ganache and show more details about transactions.

  • wow, I can't believe that was it. Thank you so much! – jasper May 18 '18 at 14:22

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.