1

I'm writing my first smart contract. At a certain point I need it to start a countdown like process, it must perform a token transfer after a certain number of blocks. This is giving me some problems.

Is there a way that's already been explored to efficiently do it?

EDIT: I want the smart contract to perform the transaction, not to schedule a transaction to be sent at a certain block height from my node

3
  • 1
    You can't schedule a transaction within the blockchain. You'll need to compete against other transactions by bidding on a slot for that block by setting a gas price. Otherwise, you could game the system by paying a low gas price in the present to avoid a crunch for space later.
    – lungj
    Commented Sep 12, 2017 at 15:07
  • @lungj thanks! I found this browsing ethereum-alarm-clock.com should do exactly what I want right? Commented Sep 12, 2017 at 20:29
  • 1
    Yes, that's what the Ethereum alarm clock is for; however, I don't know if it's being used or maintained. It requires other users to wake your function by you incentivizing them. It's not a self-contained system.
    – lungj
    Commented Sep 12, 2017 at 23:06

2 Answers 2

2

Consider a withdrawal-like pattern. I can't say specifically without more details, and this may not be exactly what you are looking for, but I think that you could learn something from this post here.

1

Actually performing a token transfer will require you to interact with the contract, which will cost your gas for every call that you'll make.

You can create a function that will check, when called, how much time has passed, using some simple logic in combination with Time Units (https://solidity.readthedocs.io/en/develop/units-and-global-variables.html).

That's one way to do it, there are of course other ways, variously implemented over some projects.

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