0

I have used Aion smart contracts to facilitate scheduling a ETH transaction. It works fine, but when it comes to making those transactions periodically (Scheduling multiple transactions), it throws an error.

What I am trying to say is that I have made one specific function that is responsible for taking two arguments ( nonce = number of payments, period = duration between payments ) beside my main scheduleTransaction() which is responsible for a single transaction scheduling, and I want to set up a group of automatic ETH transactions based on these characteristics. I'm going to attach my code. my loop seems fine, but it gives an error.

I would be thankful if anyone gives me a suggestion why whenever I try to execute scheduleMultipleTransaction(), it throws an error?

enter image description here

function scheduleTransaction(uint256 _fromNow) public {
    aion = AionContract(0x2fC197cD7897f41957F72e8E390d5a7cF2858CBF);
    uint256 callCost = 10e16 + 800000*100e9 + aion.serviceFee();
    aion.ScheduleCall.value(callCost)( block.timestamp + _fromNow, Reciever, 10e16, 800000, 100e9, hex"00", true);
}


function scheduleMultipleTransactions(uint _period, uint _nonce) public {
    for(uint i=0; i<=_period*(_nonce-1); i+_period) {
        scheduleTransaction(i);
    }
}

function () public payable {}

Lastly, I have to add that i had provided enough ETH to the contract prior to execution of these functions

1 Answer 1

1

The code below is shown in the help for recurrent transactions:

pragma solidity ^0.4.24;

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

}

// Main contract
contract MyContract{
    Aion aion;

    constructor() public payable {
        scheduleMyfucntion();
    }

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

    function myfucntion() public {
        // do your task here and call again the function to schedule
        scheduleMyfucntion();
    }

    function () public payable {}

}

This code calls the function MyFunction every 24 hours. So the code that you want to execute every time should be included in Myfunction, for instance

function myfucntion() public {
    // do your task 
    (someAddress).transfer(amount);
     // then reschedule the transaction
     scheduleMyfucntion();
    }

That should work.

Hope this helps.

1
  • Thanks to BRO JAIMEEEEEEEEEEEEEE the King Commented Nov 27, 2021 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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