Solidity Sending ERC20 Tokens

+1 vote

I have a solidity contract that has minted a fixed number of ERC20 tokens (using the ropsten test network). I am in need of a way to send the tokens from a wallet to another wallet (preferrably the using the web3js library, but JSON-RPC would work, I have the private key to the account).

Here is my code thus far

var Web3 = require('web3')
var web3 = new Web3(new 
Web3.providers.HttpProvider('https://ropsten.infura.io/xxxxxxx'));
const abi = [ {} ];
const contract = new web3.eth.Contract(abi).at("0x...")
contract.transferFrom('0x....', '0x.....', 100);

When I execute this snippet, I get issues saying "TypeError: (intermediate value).at is not a function". I am relatively new to web3, so any thoughts/suggestions would be most appreciated.

Sep 26, 2018 in Blockchain by digger
• 26,740 points
1,422 views

1 answer to this question.

0 votes

You can try this code

transferTokensTo: function(contract, address_from, address, tokens) {
    return new Promise(function(resolve, reject) {
        contract.methods.decimals().call().then(function (result) {
            var decimals = result;
            console.log("Token decimals: " + decimals);
            var amount = tokens * Math.pow(10, decimals);

            console.log('Transfer to:', address);
            console.log('Tokens: ' + tokens + " (" + amount + ")");
            contract.methods.transfer(address, amount).send({
                from: address_from,
                gas: 150000
            }).on('transactionHash', function (hash) {
                console.log('\n[TRANSACTION_HASH]\n\n' + hash);
            }).on('confirmation', function (confirmationNumber, receipt) {
                console.log('\n[CONFIRMATION] ', confirmationNumber);

                resolve(receipt);
            }).on('receipt', function (receipt) {
                console.log('\n[RECEIPT]\n\n', receipt);

                // TODO: process receipt if needed
            }).on('error', function (error) {
                console.log('\n[ERROR]\n\n' + error);

                reject(error);
            }).then(function (done) {
                console.log('\n[DONE]\n\n', done);
            });
        });
    });
}
answered Sep 26, 2018 by slayer
• 29,350 points

Related Questions In Blockchain

0 votes
1 answer

Can I execute distributions in ERC20 tokens on a later stage?

It is best to have a claim ...READ MORE

answered Nov 2, 2018 in Blockchain by Prerna
• 1,960 points
630 views
0 votes
1 answer

How to set the ERC20 token price in respect to ether in solidity?

Hi, @Jas, I would suggest you go through ...READ MORE

answered Nov 9, 2020 in Blockchain by anonymous
• 10,520 points
4,926 views
+1 vote
1 answer

Getting issues while Sending signTransaction with web3.js

The chain ID for ropsten is 3. ...READ MORE

answered Mar 28, 2018 in Blockchain by Johnathon
• 9,090 points
3,318 views
0 votes
1 answer

What is the difference between if() and require() statement in solidity??

If() and require() have separate functions and ...READ MORE

answered Apr 18, 2018 in Blockchain by Shashank
• 10,400 points
4,781 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,683 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,226 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,210 points
1,245 views
0 votes
1 answer

How to write a program to get details of ERC tokens?

You can use Javascript with the Metamask ...READ MORE

answered Jul 13, 2018 in Blockchain by slayer
• 29,350 points
723 views
0 votes
1 answer

Solidity code to change value of name

Try this for setName: function setName(string _name) public ...READ MORE

answered Jul 30, 2018 in Blockchain by slayer
• 29,350 points
1,054 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP