I have created a smart contract in which a "stop()" function should be called once a deadline is reached. Dapp is keeping check of the deadline and as soon as the deadline is reached I need to call this function, the function itself actually sends some amount of ethers to 3 different addresses.
Here is the stop function:
function stop() public{
require(now > deadline, "deadline expired");
require(address(this).balance >= 1 ether, "contract doesnot have sufficient ethers");
// quickSort(top, 0, top.length-1);
for(uint i = 0; i < registeredStudents; i++)
sort(i);
// distribute the tokens
for(uint i = 0; i <= 2; i++){
students[top[i]].wallet.transfer((3-i) * 100000000000000000);
emit Transferred(students[top[i]].wallet, top[i], 3-i);
students[top[i]].totalBalance += (3-i) * 100000000000000000;
}
}
How can I call this function from the Dapp? I tried using call() but it is not working and I tried send() too but send() wants me to give from address as well, which I dont know should be what in this case.
Please suggest. It is urgent task. Thanks in advance.