Go-Ethereum

使用 SmartContract 通過單個 Transaction 將乙太幣發送到 multiAddress 但它沒有在 multiAccount 中獲取乙太幣

  • March 1, 2018

我已經使用了已經生成的合約地址:https ://etherscan.io/address/0xb59fdff77a6175dfa4fe7af4281a52f61611eaa2#code

並使用這個我在下面的程式碼中創建:

// Include the packages
const Web3 = require('web3')
//const abi = require('human-standard-token-abi')
var abi = [{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_tokenAddr","type":"address"},{"name":"dests","type":"address[]"},{"name":"values","type":"uint256[]"}],"name":"multisend","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"type":"function"}];




// Set up Infura as your RPC connection
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));


// Define the contract addresses and the contract instance
const contractAddress = '0xb59fDfF77a6175DFA4fE7aF4281a52f61611eAa2'
//const contract = new web3.eth.contract(abi, contractAddress)

var contractAbi = web3.eth.contract(abi);
var contract = contractAbi.at(contractAddress);
// suppose you want to call a function named myFunction of myContract




fetch('http://localhost:8545', {
   method: 'POST',
   headers: {
       'Accept': 'application/json', 'Content-Type': 'application/json' },
   body: JSON.stringify({ 'method': 'personal_unlockAccount', 'params': ["0x2885f9904f3d1790ba53009bc9e0baae377d67df","kiranmalvi",null], 'id': 1, 'jsonrpc': '2.0' }) })
   .then(function (res) {


       contract.multisend.sendTransaction('0x627306090abaB3A6e1400e9345bC60c78a8BEf57',["0x2885f9904f3d1790ba53009bc9e0baae377d67df","0x7b7cd7d5cee9fb36b7995a3d81df0122a0b1af4a"],["100","200"],{
           from:"0x2885f9904f3d1790ba53009bc9e0baae377d67df",
           gas:4000000 },function (error, result){
           if(!error){
               console.log(result);
           } else{
               console.log(error);
           }
       })

   });

但是交易並沒有分配我定義的多個地址它只是發送合約地址中的所有金額。你能幫我我該怎麼做嗎?

嘗試像這樣替換 fetch 部分。

web3local.personal.unlockAccount(addr, pass);
tokenlocal.multisend(tokenAddress,["0x2885f9904f3d1790ba53009bc9e0baae377d67df","0x7b7cd7d5cee9fb36b7995a3d81df0122a0b1af4a"],["100","200"], { from: addr }, function (err, txHash) {
   if (err) {
       console.error(err);
   }
 if (txHash) {
   console.log(txHash)
 }
})

編輯 剛剛檢查了您的程式碼。有幾點需要注意。

  • 您不是發送 ETH,而是發送代幣
  • 您沒有將令牌數量轉換為其基本單位值。例如,如果您的代幣的小數位數為 5,則當您發送 10 個代幣時,將被視為 0.00010。您可能需要為此更改您的智能合約。

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