1

I am new to etherum blockchain.

I am working on designing the contract for payment money.

The customer must pay money for rent space for every 1 month, or the contract will be invalid.

How can my smart contract check that payment is not paid for every moth? and then update status of that contract automatically?

Alongkorn
  • 289
  • 2
  • 7
  • 1
    The smart contract can't. You must do this from an off-chain service. You can either build your own, or use custom ones like Oraclize (which requires you to add designated callback infrastructure in your contract). – goodvibration Jan 13 '19 at 10:12

1 Answers1

1

You will need an external service as smart contracts cannot do this in ethereum.

You can use Aion scheduling system to do what you ask.

Assume the contract that checks the payment is like this:

pragma solidity ^0.4.25;    
contract paymentCheck{        
    function Check(){
        // do here you checking code 
    }        
}

You can use Aion to call your checking function every 30 days, using this:

// interface Aion
contract Aion {
    uint256 public serviceFee;
    function ScheduleCall(uint256 blocknumber, address to, uint256 value, uint256 gaslimit, uint256 gasprice, bytes data, bool schedType) public payable returns (uint,address);

}

contract paymentCheck{
    Aion aion;

    function scheduleCheck() public {
        aion = Aion(0xFcFB45679539667f7ed55FA59A15c8Cad73d9a4E);
        bytes memory data = abi.encodeWithSelector(bytes4(keccak256('Check()')));
        uint callCost = 200000*1e9 + aion.serviceFee();
        aion.ScheduleCall.value(callCost)( block.timestamp + 30 days, address(this), 0, 200000, 1e9, data, true);
    }

    function Check(){
        // do here you checking code 
    } 
    function () public payable {}

}

You call the function scheduleCheck() once and the system will call your Check function every 30 days (in this exmaple).

Aion is free to use in ropsten so you can give a try (change the period to a 10 or 20 minutes to test)

The advantages over oraclize are that Aion system is trustless (Oraclize is not), and on every call, your contract receive all the gas that was not used (in Oraclize the gas unused is lost)

Other solutions based on ethereum alarm clock (EAC) are expensive in gas consumption, for instance every call using EAC is about 500K gas, while in Aion the gas cost of the first call is about 300K gas but after the first call the next ones cost about 70K. Also the Fees in EAC are way higher because you need to provide a bounty. The only fee in Aion is about 0.0005 ETH.

Hope this helps

Jaime
  • 8,340
  • 1
  • 12
  • 20