2

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".

TylerH
  • 20,799
  • 66
  • 75
  • 101
Viper
  • 1,327
  • 2
  • 12
  • 33
  • Refer to this [answer](https://stackoverflow.com/a/50019666/6521116) of [Send ERC20 token with web3](https://stackoverflow.com/q/48180941/6521116) – LF00 Apr 25 '18 at 12:54

1 Answers1

1

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);
            });
        });
    });
}
Dmytro Zarezenko
  • 10,526
  • 11
  • 62
  • 104