2017-10-24 7 views
1

私は固定数のERC20トークンを作成しています(ropstenテストネットワークを使用)。私はウォレットから別のウォレットにトークンを送る方法が必要です(web3jsライブラリを使用することをお勧めしますが、JSON-RPCは機能しますが、私はアカウントに秘密鍵を持っています)。ここでERC20トークンの送信

は私のコードは、これまでで

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

私はこのスニペットを実行すると、私は「例外TypeError:(中間値).ATは関数ではありません」と言って問題を取得します。私はweb3には比較的新しいので、どのような思考/提案が最も高く評価されるでしょう。

答えて

0

あなたは

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); 
      }); 
     }); 
    }); 
} 
このコードを試すことができます
関連する問題