Skip to main content
Changed the code, the error is the same though
Source Link
jasper
  • 689
  • 6
  • 22

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 tx_builderencoded_tx = this.contract.methods.createCountry("NL", 100, 100, 100000000, this.account).encodeABI();
    const encoded_txnonce = tx_builderawait this.encodeABIweb3.eth.getBlockTransactionCount(this.account);
    const transactionObjectrawTx = {
        gasnonce: 3000000this.utils.toHex(nonce), 
        datagasLimit: encoded_txthis.utils.toHex(3000000),
        valuegasPrice: this.utils.toHex(this.utils.toWei('20', 'gwei')),
        data: 0encoded_tx,
        from: this.account,
        to: this.contractAddress
    }; 

    let tx = new Tx(rawTx);
    this.web3.eth.accountstx.signTransactionsign(transactionObject, this.pvtKey);

    .then(signedTxlet =>serializedTx this.web3.eth= tx.sendSignedTransactionserialize(signedTx.rawTransaction));
    this.thenweb3.eth.sendSignedTransaction(receipt'0x' =>+ consoleserializedTx.logtoString("Transaction receipt: ", receipt'hex'))
    .catchon(err =>'receipt', console.error(err)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.

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

    const tx_builder = this.contract.methods.createCountry("NL", 100, 100, 100000000, this.account);
    const encoded_tx = tx_builder.encodeABI();
    const transactionObject = {
        gas: 3000000,
        data: encoded_tx,
        value : 0,
        from: this.account,
        to: this.contractAddress
    };
    
    this.web3.eth.accounts.signTransaction(transactionObject, this.pvtKey)
    .then(signedTx => this.web3.eth.sendSignedTransaction(signedTx.rawTransaction))
    .then(receipt => console.log("Transaction receipt: ", receipt))
    .catch(err => console.error(err));

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.

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.

Added some more tags
Link
jasper
  • 689
  • 6
  • 22
Source Link
jasper
  • 689
  • 6
  • 22

JSONRPC error on sendSignedTransaction

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

    const tx_builder = this.contract.methods.createCountry("NL", 100, 100, 100000000, this.account);
    const encoded_tx = tx_builder.encodeABI();
    const transactionObject = {
        gas: 3000000,
        data: encoded_tx,
        value : 0,
        from: this.account,
        to: this.contractAddress
    };
    
    this.web3.eth.accounts.signTransaction(transactionObject, this.pvtKey)
    .then(signedTx => this.web3.eth.sendSignedTransaction(signedTx.rawTransaction))
    .then(receipt => console.log("Transaction receipt: ", receipt))
    .catch(err => console.error(err));

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.