2

I have code to transfer Ether to an address, as follows:

addr.transfer(amount);

Unfortunately, when I execute this statement for two transfers, the money never arrives in the addr addresses. I do see the Etherscan output on Ropsten:

enter image description here

I have a suspicion the transfers (call_1_0 and call_1_1 below) are never fulfilled, because the GasLimit is set to 2300. Is this possible?

Is there a way to increase the GasLimit? I tried using:

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

but then the solc compiler says:

TypeError: Member "gas" not found or not visible after argument-dependent lookup in function (uint256)
addr.transfer.gas(GAS_LIMIT)(amount);
^---------------^

This is the full code of the contract (beneficiaries are added during construction by a "manager" contract that instantiates it.

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

}

How can I transfer money to the user addresses from the contract?

  • Looking at ropsten.etherscan.io/tx/…, it seems that both transfer were done correctly. The second is to ropsten.etherscan.io/address/… you should look at the "Internal Transaction" tab, there's a line where "Parent Hash" is 0xdd6c0059b330dc... the block is 1287872 the transfer for 0.05402... Ether. – Ismael Jul 23 '17 at 1:12
  • @Ismael thanks. So the ETH was added to account 0xbC965738eAbb38d15dc5d0B63Ec1420EAb5df2BC? I just have to look at internal transactions, and not transactions or the MetaMask wallet? :) – Erwin Rooijakkers Jul 23 '17 at 12:33
  • Yes, usually "internal transactions" are not tracked by wallets because no easy interface exist to access them yet. – Ismael Jul 23 '17 at 15:22
  • 1
    @Ismael Thanks! This solves my problem. If you want you can add your comment as answer so I can accept it. – Erwin Rooijakkers Jul 24 '17 at 15:45
4

Looking at your transaction 0xdd6c0059b330dc... both transfer were done correctly.

For example the second transfer is to address 0xbc965738eabb38..., you should look at the "Internal Transaction" tab, there's a line where "Parent Hash" is 0xdd6c0059b330dc... and block is 1287872 for an amount of 0.05402... Ether.

Usually "internal transactions" are not tracked by most wallets because it requires processing each transaction, and there's no public api to access them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.