How to transfer erc20 token without using contract or contract abi?

The below script i have used to create Signed Raw Transaction to send Ether(ETH).
How can i create Signed Raw Transaction to send erc20 token with the same script by doing some modifications
what modifications are actually required i want to know and also i do not want to use smart contract abi.

var rawTx = {
  nonce: '0x1a',
  gasPrice: '0x4a817c800',
  gasLimit: '0xc350',
  to: '0x73F7Ced8cc9D27DC426210c32fc6d0a40f941eE1',
  value: '0x2386f26fc10000',
  data: '0x0',
  chainID: 4 
var cTx = await new EthereumTx(rawTx, { 'chain': 'rinkeby' });
var serializedTx = await cTx.serialize();
var cTxHash = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
  • You should encode the details (from , to, amount and function signature) and give it as data instead of '0x0' and 'to' is the address of the smart contract, 'value' should be 0. Anyway I'm sure someone asked about this before, if you didn't find an answer until tomorrow, I will weite a simple script for you – Majd TL Feb 12 '20 at 19:03
  • i didn't get answer, – Ishwar Chandra Tiwari Feb 12 '20 at 19:25

You have to encode tha call to transfer into the data field.

  • 4 bytes function signature of transfer(address,uint256)
  • 32 bytes address parameter right aligned filled with zero bytes on the left
  • 32 bytes amount paramter

For example if you want to transfer 0.2 DAI to 0xaaBBCcDDEeff00112233AaBbCcdDeEfF00112233.

Your data field will be

  • a9059cbb (function signature)
  • 000000000000000000000000aabbccddeeff00112233aabbccddeeff00112233 (tokens recipient)
  • 00000000000000000000000000000000000000000000000002c68af0bb140000 (200000000000000000 because DAI uses 18 decimals)

So your raw transaction will be:

var rawTx = {
  nonce: '<whatever>',
  gasPrice: '<whatever>',
  gasLimit: '<whatever>',
  to: '0x6b175474e89094c44da98b954eedeac495271d0f', /// <---- DAI adress!!!!
  value: '0x0',
  data: '0xa9059cbb000000000000000000000000aabbccddeeff00112233aabbccddeeff0011223300000000000000000000000000000000000000000000000002c68af0bb140000',
  chainID: 4 

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.