Testnets
我的 Dapp 在私有測試網上工作,但不在公共測試網上工作
我創建了這個簡單的 Dapp,它可以在 Remix 內部和外部使用 Web 界面的私有測試網和 java VM 中正常工作。當它將用於“公共”測試網(Ropsten)時,問題就來了。它發送交易並執行功能,但從不將乙太幣從合約發送到地址。我已經將契約的價值設置為正確的價值。
對不起英語不好
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); } } }
在照片中,我將契約價值錯誤地放在了最後一張照片中,我將更正它。基本上現在部署者支付 4 乙太幣 + 交易成本。“伴奏”直接轉到技術人員地址。其餘的保留在契約中。
這是錢的變化(在第一次嘗試中,只有契約的第一部分運作良好,因為價值不夠)
我在 receiveReward 電話中重新製作了整個交易,剩下的部分交給了技術人員,一切都按照我的意願工作。
為什麼在 Ropsten 測試網中它不起作用?它不發送乙太幣還是我看錯了方向?
試試這個,邏輯上應該是一樣的。我發現了幾個語法錯誤:
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); } }