[英]Sending ERC20 Tokens
我有一個 Solidity 合約,它鑄造了固定數量的 ERC20 代幣(使用 ropsten 測試網絡)。 我需要一種將令牌從錢包發送到另一個錢包的方法(最好使用 web3js 庫,但 JSON-RPC 可以工作,我有帳戶的私鑰)。
到目前為止,這是我的代碼
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: (intermediate value).at is not a function”的問題。 我對 web3 比較陌生,所以任何想法/建議都將不勝感激。
你可以試試這個代碼
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);
});
});
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.