Web3js

使用 web3@1.0.0 發送 ERC20 令牌的問題

  • July 29, 2018

環境

我已經遵循了這個 GH問題其他SO 文章的所有跡象。交易成功廣播,但沒有代幣轉移。

當我在執行程式碼之前和之後檢查餘額時,我得到相同的結果:10000,這是原始供應量。

const Tx = require('ethereumjs-tx');

const config = require('../config');
const contract = require('../contract')('PaulCoin', config.contracts[0]);
const web3 = require('../web3');

const main = async () => {
   try {
       const count = await web3.eth.getTransactionCount(config.accounts[0]);
       const nonce = web3.utils.toHex(count);
       const txValue = web3.utils.toHex(parseInt(process.argv[2], 10) || 10);

       const from = web3.utils.toChecksumAddress(config.accounts[0]);

       const to = web3.utils.toChecksumAddress(config.accounts[1]);
       const rawTx = {
           nonce: nonce,
           from: from,
           to: to,
           value: '0x0',
           gasLimit: '0x30D40', // 54,000
           gasPrice: '0x2CB417800', // 12 gwei
           data: contract.methods.transfer(to, txValue).encodeABI(),
           chainId: '0x03'
       };

       const privateKey = Buffer.from(config.private, 'hex');
       const tx = new Tx(rawTx);
       tx.sign(privateKey);
       const serializedTx = tx.serialize();

       const receipt = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'));
       console.log(`Receipt info:  ${JSON.stringify(receipt, null, '\t')}`);

       console.log(`From\'s balance after transfer: ${await contract.methods.balanceOf(from).call()}`);
       console.log(`To\'s balance after transfer: ${await contract.methods.balanceOf(to).call()}`);
   } catch (err) {
       console.log(err);
   }
};

main();

環境

  • 節點9.3.0
  • 網路31.0.0-beta.35
  • 英富拉ropsten
  • osx 13.13.5

交易被發送到 address ,這0x19149798f777a3d738777334ccbf0063a04fca3b不是契約。

不會發生 ERC20 轉賬,因為沒有交易被發送到 ERC20 代幣合約。

引用自:https://ethereum.stackexchange.com/questions/55353