0

I want to create a contract asset that pays out 1 Ether every 1000 blocks, but only pay out up to 10 Ethers. I want to pay the asset holder. So that means the asset can be transferred to someone else and the contract will be paying to that person.

My questions are:

  • What happens if I have less than 10 ether's in my account when this contract first runs? Does it still run?
  • Will the contract run itself when it reaches 1000 blocks each time? Or do you have to run it manually?
1

Q1:

This is a matter of how the contract is written. It would seem reasonable to make it a requirement to have sufficient funding to "back" all liabilities. It's not a property of Ethereum, but it could (should?) be a property of the contract.

Q2:

The contract is not going to run on a continuous basis. There are several methods to achieve the periodic payment. Among these are:

  1. An "admin"/"maintenance" client periodically triggers a function.
  2. "Ethereum Alarm Clock" which is a contract that works sort of like a cron job, or
  3. Beneficiary triggers a "claim" function and the contract merely validates the request.

In my opinion, the third option is best. The beneficiary is incentivized to claim their entitlement. They watch the block count and hold their fire until 1,000 blocks passes and then send a transaction to trigger the asset transfer. They pay the gas for the transfer.

The contract "sleeps" until a transaction wakes it up.

The contract then has a set of rules to confirm the claim is valid. Has it been 1,000 blocks since the previous payout? Has less than 10 been paid so far? In the case that the claim is not valid, the contract simply throws and destroys the gas.

Hope it helps.

1

What happens if I have less than 10 ether's in my account when this contract first runs? Does it still run?

You're creating the contract so it's up to you what it does, but the obvious way to do it would be to have a variable called something like isActive, which defaults to false, then when it's got enough ETH you send it a transaction to a function called activate, which checks that it has enough money and sets isActive to true. When someone calls it to get it to do something, have it check isActive and only run if it has been activated (therefore if it has been fully funded).

Will the contract run itself when it reaches 1000 blocks each time? Or do you have to run it manually?

Contacts never run themselves. Somebody have to call it to make it do something, and a single call makes it execute once and only once, within a single block.

The obvious thing would be for whoever is getting the money to call the contract. When called, the contract checks that it hasn't been called within the last 1000 blocks, and pays the money, and stores the current block number ready for the next time it has to check.

Another option is to use the Ethereum Alarm Clock, which allows you to schedule and pay for calls in advance, and have some arbitrary person out there on the internet call them for you.

Be aware that you shouldn't rely on your contract being called at a specific block number; If the miner who mines block 4,567,000 decides not to include a transaction you send them, it won't get called, even if your transaction was sent at the right time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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