0

I have created this simple Dapp and it work fine in the private testnet & java VM inside Remix and outside it using a web interface. The problem come when it will be used in the "public" testnet (Ropsten). It send the transaction and execute the function but never send the ether from the contract to the address. I' ve already set the value of the contract to the correct value.

Sorry for bad English

pragma solidity ^0.4.0;

contract DApp
{
    uint256 acconto;
    uint256 saldo;
    address committent;
    address technician;
    bool done = false;
    uint timeFinish;

modifier onlyCom
{
    if (msg.sender != committent)
    {
        assert(true);
    }
    else
    {
        _;
    }
}

function DApp (uint256 _acconto, uint256 _saldo, address _technician, uint _Time) payable public
{
    if (msg.value >= _acconto + _saldo) {
    acconto = _acconto * 1000000000000000000;
    saldo = _saldo * 1000000000000000000;
    committent = msg.sender;
    technician = _technician;
    timeFinish = block.timestamp + _Time;

    technician.transfer(acconto);
    } else revert();
}

function Done () public onlyCom
{
    done = true;
}

function reciveReward () payable public
{
    if(done == true)
    {
        technician.transfer(saldo);
        selfdestruct(this);
    }
    else
    {
        if(block.timestamp >= timeFinish)
        {
            committent.transfer(saldo);
            selfdestruct(this);
        }

        assert(true);
    }
}
}

Edit: This is how it should work: enter image description here I write the data for the transaction

enter image description here In the photo I putted the value of contract with an error, I will correct it in the last photo. Basically now the deployer is paying 4 ether + transaction cost. The "acconto" goes directly to the technician address. The rest remains into the contract.

enter image description here This is the change of money (In the first try only the first part of the contract worked fine because the value wasn' t enough)

enter image description here I remaded the whole transaction at the receiveReward call the remaining part goes to technician and all worked as I wanted.

Why in the Ropsten Test Net it doesn' t work? It doesn' t send ether or am I looking in the wrong direction?

  • sembra scritto male di proposito – user38075 May 30 '18 at 20:47
  • @siid scusa se non posseggo il tuo livello di inglese, :( – Tommaso Giubilei May 31 '18 at 15:38
  • Non mi riferivo all'inglese – user38075 May 31 '18 at 15:45
  • @siid a cosa allora? – Tommaso Giubilei May 31 '18 at 16:03
  • al codice solidity – user38075 May 31 '18 at 16:20
0

Try this, should be logically identical. I found a couple of syntax errors:

pragma solidity ^0.4.0;

contract DApp {
    uint256 acconto;
    uint256 saldo;
    address committent;
    address technician;
    bool started;
    uint256 timeFinish;

    modifier onlyCom() { require(msg.sender == committent); _; }
    modifier onlyAfter(uint _time) { require(now > _time); _; }

    constructor (uint256 _acconto, uint256 _saldo, address _technician) public {
        technician = _technician;
        committent = msg.sender;
        acconto = _acconto;
        saldo = _saldo;
        started = false;
    }

    function start(uint256 _time) public onlyCom() payable {
        require(started == false);
        require(msg.value >= acconto + saldo);
        started = true;
        timeFinish = now + _time;
        technician.transfer(acconto);
    }

    function good() public onlyCom() { selfdestruct(technician); }
    function bad() public onlyCom() onlyAfter(timeFinish) { selfdestruct(committent); }
}
  • The acconto & saldo is now in ether or wei, because it doesn' t multiply for nothing. L' acconto e il saldo ora sono in ether o wei, perché non è moltiplicato per nulla come nel mio programma... Lo devo poi moltiplicare nell' interfaccia con web3? – Tommaso Giubilei Jun 1 '18 at 6:21
  • secondo me conviene, si – user38075 Jun 1 '18 at 10:04
  • Funziona, grazie mille – Tommaso Giubilei Jun 1 '18 at 21:40
2

Some issues that appears when switching from a private testnet to a public network:

  • Not enough gas. Some IDEs and wallet can estimate the correct value of gas required by a transaction, but when your program creates the transaction it will use a default value that can be not enough (it used to be 100k).

  • Gas price too low. In a private testnet often the price is fixed and all transactions will be processed. In a public testnet the gas price will fluctuate with the demand. Low gas price might cause a transaction to take longer to be mined.

  • Not waiting for confirmation of the transaction. In a private testnet transactions are confirmed quickly, but in a public network your transaction have to compete with others pending transactions for space in blocks. It might take several blocks before your transaction is confirmed, and until them your contract will not reflect the changes made in the transaction.

  • I checked all of this multiple time but it continue to don' t work. What can I do? Sorry for bad English – Tommaso Giubilei May 30 '18 at 20:31
  • Do you have the transaction id when it failed? It seems your parameters _acconto, _saldo are in ethers and you compare them against msg.value that is in wei. So it is possible you are sending to the contract less ethers than it required. – Ismael May 31 '18 at 2:28
  • I think this is the transaction id, but I' m not sure.. Contract creation: 0xbc63d42af64ce272a0b7517ba2daa50c579af5f7d2bae66de00672474f12fba2 Function Done: 0x66d260e9a37346998aee63657ad5fca7b5d3ccec71f8130ec7504316dc89c542 ReceiveReward: 0xc12456396112c9e241700c99927a442655e69b4671aac89db4866bb6fc148838 This is the testnet test, the one in the photo is on Virtual Machine. Testnet Ropsten. Sorry for bad English – Tommaso Giubilei May 31 '18 at 15:40
  • The problem with that transactions is when you create the contract you set _acconto and _saldo to zero. When you call ReceiveReward() it transfer saldo to technician address (but it is zero!) and then it selfdestructs and it will ignore further calls. – Ismael Jun 1 '18 at 3:20
  • Why it set it to zero? I multiply the wei value for 10^18... I don' t understand why it set it to 0. But hopefully I know that it isn' t a later problem but a constructor problem. Thanks for the help – Tommaso Giubilei Jun 1 '18 at 6:14

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.