aurora-is-near / aurora-relayer

[DEPRECATED] Web3-compatible relayer server for Aurora.
https://aurora-is-near.github.io/aurora-relayer/
Creative Commons Zero v1.0 Universal
26 stars 13 forks source link

web3.eth.sendSignedTransaction #292

Closed ChandanBhindwar-zz closed 2 years ago

ChandanBhindwar-zz commented 2 years ago

Hi, I want to transfer ERC20 Tokens using web3js in aurora test network. Getting above error, When using web3.eth.sendSignedTransaction.It is giving Invalid chain_id error.Please guide me here.

var gasPriceGwei = 0;
var gasLimit = 3000000;
var chainId = 1313161555;
var rawTransaction: any = {
  "from": myAddress,
  "nonce": "0x" + count.toString(16),
  "gasPrice": this._web3.utils.toHex("0"),
  "gasLimit": this._web3.utils.toHex(gasLimit),
  "to": this._tokenContractAddress,
  "value": "0x0",
  "data": contract.methods.transfer(destAddress, transferAmount).encodeABI(),
  "chainId": this._web3.utils.toHex(chainId)
};

var privKey = Buffer.from('privKey', 'hex');
var tx = new Tx(rawTransaction);
tx.sign(privKey);
var serializedTx = tx.serialize();

var receipt = await this._web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'));

console.log(`Receipt info: \n${JSON.stringify(receipt, null, '\t')}\n------------------------`);
// The balance may not be updated yet, but let's check
balance = await contract.methods.balanceOf(myAddress).call();
// console.log(`Balance after send: ${financialMfil(balance)} `);

Thank you Screenshot from 2022-05-19 15-56-44 .

paouvrard commented 2 years ago

Have you tried setting the chain argument like in the example? https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#id93 var tx = new Tx(rawTransaction, {'chain': 1313161555 }); Docs mention that When using ethereumjs-tx@2.0.0 if you don’t specify the parameter chain it will use mainnet by default.

ChandanBhindwar-zz commented 2 years ago

image

Yes, I get above error.

paouvrard commented 2 years ago

It appears that ethereumjs-tx does not work well with custom chains atm, I'd recommend ethersjs for this.

For using ethereumjs with custom networks you can look into these docs: https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/tx/examples/custom-chain-tx.ts https://github.com/ethereumjs/ethereumjs-tx#chain-and-hardfork-support https://github.com/ethereumjs/ethereumjs-common#working-with-privatecustom-chains

Let's close this issue as it is related to ethereumjs-tx signer and not aurora-relayer. Feel free to continue the discussion in TG if you require more assistance.

ChandanBhindwar-zz commented 2 years ago

It is resolved now. Thank you.

TanyaSrivastava-Dipali commented 2 years ago

It is resolved now. Thank you.

Could You please share your code.

shubhamgacche commented 2 years ago

Hello Chandan @ChandanBhindwar, i am also facing the same issue ...could you please share your code or details on how you resolved the same .....Thank you.