Solidity

將乙太幣從合約轉移到使用者地址

  • August 24, 2017

我有將乙太幣轉移到一個地址的程式碼,如下所示:

addr.transfer(amount);

不幸的是,當我為兩次轉賬執行此語句時,錢永遠不會到達addr地址。我確實在 Ropsten 上看到了 Etherscan 輸出:

在此處輸入圖像描述

我懷疑轉賬(下面的 call_1_0 和 call_1_1)從未完成,因為 GasLimit 設置為 2300。這可能嗎?

有沒有辦法增加 GasLimit?我嘗試使用:

 uint GAS_LIMIT = 4000000;
 addr.transfer.gas(GAS_LIMIT)(amount);

但是solc編譯器說:

TypeError:在函式(uint256)

addr.transfer.gas(GAS_LIMIT)(數量)中依賴參數查找後,成員“gas”未找到或不可見;

^—————^

這是合約的完整程式碼(受益人是在建構過程中由實例化它的“經理”合約添加的。

contract SimpleSmartAsset is Mortal {

 uint usagePrice;
 Beneficiary[] beneficiaries;
 uint totalWeight; // to calculate percentage the beneficiaries receive

 event AssetCreated(uint _usagePrice,
                    address[] addresses,
                    uint[] weights);

 function SimpleSmartAsset(uint _usagePrice,
                           address[] addresses,
                           uint[] weights) {
   owner = msg.sender;
   usagePrice = _usagePrice;

   uint beneficiaryCount = addresses.length;
   for (uint i = 0; i < beneficiaryCount; i++) {

     uint weight = weights[i];

     addBeneficiary(addresses[i], weight);
     totalWeight += weight;
   }

   AssetCreated(_usagePrice, addresses, weights);
 }

 function getUsagePrice() constant returns (uint) {
   return usagePrice;
 }

 event BeneficiaryPaid(address addr, uint amount);

 function pay() payable onlyOwner {
   require(msg.value >= usagePrice);

   uint beneficiaryCount = beneficiaries.length;
   for (uint i = 0; i < beneficiaryCount; i++) {

     Beneficiary memory beneficiary = beneficiaries[i];

     uint weight = beneficiary.weight;
     address addr = beneficiary.addr;

     uint amount = (weight * usagePrice) / totalWeight;

     uint GAS_LIMIT = 4000000;
     addr.transfer.gas(GAS_LIMIT)(amount);
     BeneficiaryPaid(addr, amount);
   }
 }

 struct Beneficiary {
   address addr;
   uint weight;
 }

 function addBeneficiary(address addr, uint weight) onlyOwner {
   beneficiaries.push(Beneficiary({
       addr: addr,
       weight: weight
   }));
 }

}

我如何將錢從合約中轉移到使用者地址?

查看您的交易 0xdd6c0059b330dc …兩次轉賬都正確完成。

例如第二次轉賬是到地址 0xbc965738eabb38…,你應該看一下“內部交易”選項卡,有一行“父雜湊”0xdd6c0059b330dc...和塊是12878720.05402… 乙太。

通常大多數錢包不會跟踪“內部交易”,因為它需要處理每筆交易,並且沒有公共 api 可以訪問它們。

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