Deploy the ethereum contract token and transfer token from one address to other address using node js web3.Anyone please help me.
3 Answers
I found that this article explains well how to do this. source code is available, and you may like to modify it slightly to your purpose.
https://hackernoon.com/how-to-script-an-automatic-token-airdrop-for-40k-subscribers-e40c8b1a02c6
Here is the function that generates a transaction that performs an ERC-20 transfer:
async function TransferTokens(_TO, _AMOUNT){
const ERC_CONTRACT_ADDR = "0x0" // your contract
const ABI_FILE = "ABI.json"; //your abi
const ERC_CONTRACT = new web3.eth.Contract(JSON.parse(ABI_FILE), ERC_CONTRACT_ADDR);
const fromAddress = ""; // your address with tokens
const fromPrivateKey = "XXX"; //your private key
return new Promise(async function(resolve, reject){
let params = await ERC_CONTRACT.methods.transfer(_TO, _AMOUNT).encodeABI();
let rawTX = await generateTransaction(params, fromAddress, fromPrivateKey, ERC_CONTRACT_ADDR);
try{
let hash = await broadcastTransaction(rawTX);
resolve(hash);
}catch(e){
reject(e);
}
})
}
This tutorial literally explains exactly how to do this.
-
We have successfully created contract token using a crypto-currency token code (ethereum.org/token). When transfer token from one address to other address it's not working in Node js but which is works in Geth compiler.We need transfer token using Node js web3.Anyone, please fix this issue. Commented Aug 16, 2017 at 5:08
-
The mentioned article only goes through the token creation, but the question is aimed at using Node to do token transfers. Commented May 10, 2018 at 10:11