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 
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
• 27,620 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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);

            }).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);

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

Related Questions In Blockchain

0 votes
1 answer
+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,050 points
+1 vote
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,330 points
+1 vote
1 answer

what is use of msg.sender in solidity code?

msg.sender(address) function indicated the sender of the ...READ MORE

answered Apr 24, 2018 in Blockchain by Shashank
• 10,330 points
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
0 votes
1 answer
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
• 65,840 points
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,040 points
0 votes
1 answer

Solidity code to change value of name

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

answered Jul 29, 2018 in Blockchain by slayer
• 29,040 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.