Something I would like to know about smart contracts

torwenttorwent Posts: 6Member
So... I've known about ethereum for a while and I understand most of it
Basically it's like a computer running on a block gain, therefore you can program it to do stuff, aka "smart contracts".

I've been searching quite a bit for this answer without finding anything so here goes...


From what I know, smart contracts are contracts that execute with no way from being stopped.
For example if two people bet 1 eth that ethereum will be worth 1000usd on 1/1/2018, when that day arrives if ethereum would be worth 1000usd the person that lost the bet would automatically pay 1 eth to the other without being able to stop it in anyway.

What I don't understand is... what would happen if the person that would lose the bet, traded all his eth to another wallet 1 day before?
1/1/2018 would arrive, he would lose the bet but have no balance to pay the bet right?

At first I thought maybe the smart contracts would lock the value from the people taking part on the contract, for example, with the bet above, as the contract starts running, both people would lose 1 ether each that would be kept with the contract and when 1/1/2018 arrives the winner would be paid 2 eth.

Which is how I think it works.

However that would be a problem in a contract that instead of saying the bet loser had to pay out 1 eth to the winner, said instead the loser had to pay 1eth every month for the rest of his life.
As there's no definitive value to be paid out, how would it work?

Can someone more knowledgeable about this explain to me how it really works?

Comments

  • qqwyqqwy Posts: 15Member
    A contract has no control over the things that are outside of it.

    So indeed, the (most simple) way the contract could work, is by both people 'locking' the bet by sending the same amount of ETH each to it, which will be kept there until 1/1/2018 has arrived.

    At that time, the contract knows which player has won, and allows this player to withdraw all ETH from the contract, while the other player cannot do so.

    Building a contract that states 'you have to pay one ETH for the rest of your life' does not work, because all other ether (not stored in the contract at this time) of a person is outside of a contract's control.
  • torwenttorwent Posts: 6Member
    I already got the information from reddit but that's a nice piece of extra info... had no idea you had to withdraw the Eth from the contract. I thought it would just be sent to you automatically
  • qqwyqqwy Posts: 15Member
    It is totally possible to send ether (and also ERC20-style tokens) directly to a person from within the contract.

    However, there is a problem with that approach, as it opens your contract to a malicious attack. Therefore, the Withdrawal Pattern is frequently employed instead.
  • o0ragman0oo0ragman0o Posts: 1,251Member, Moderator mod
    The other big problem with push payments, especially to multiple parties is that it usually requires an unbounded loop. This is problematic given the various gas limitations imposed on the system. It also means that if payment to one recipient fails, it can throw the whole contract, preventing payment to the others also.
Sign In or Register to comment.