1

When I try to send funds from a token address to another I encounter this error: only replay-protected (EIP-155) transactions allowed over RPC

My Code:

const contract = new web3.eth.Contract(ABI,token_contract_address);

    const data = contract.methods.transfer(to, req.body.value).encodeABI();

    const rawTransaction = {
        'from': from,
        'nonce': web3.utils.toHex(web3.eth.getTransactionCount(from)),
        'gasPrice': web3.utils.toHex(web3.eth.gasPrice),
        'gasLimit': web3.utils.toHex(21000),
        'to': token_contract_address,
        'value': 0,
        'data': data,
        'chainId': web3.utils.toHex(chainid)
    };

    const privateKey = new Buffer.from(req.body.PrivateKey, 'hex');
    const tx = new Tx(rawTransaction);
    tx.sign(privateKey);

    const serializedTx = tx.serialize();
    web3.eth.sendSignedTransaction(('0x' + serializedTx.toString('hex')),req.body.PrivateKey) 
    .then(function (result) {
        res.statusCode = 200;
        res.setHeader('Content-Type', 'application/json');
        res.json(result*decimals);
        console.log(result);
    })
    .catch((err) => next(err));

Notice I have already added ChainId

4
  • Please let us know what Ethereum node are you using – Mikko Ohtamaa May 31 at 10:57
  • Same issue here using Infura's Matic endpoint – Neozaru Jun 21 at 10:30
  • @MikkoOhtamaa there was some problem node I was using, now it works s expected. – Shivam Jun 21 at 14:05
  • @Neozaru make sure you have added chainID – Shivam Jun 21 at 14:06

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.