Coder Social home page Coder Social logo

coinlock's Introduction

Coin Lock

Smart contract that locks your coins up for a predetermined time period, expressed as the number of seconds since the Unix epoch (which is the same format as block timestamps). This software is published as-is. It's worked in testing, but there are always unforseeable things that can go wrong in practice. By using it, you accept all responsibility for whatever happens to your ether.

Usage

Launch geth and wait until it's all caught up with the rest of the network. In another terminal, run geth attach and follow the example below.

> eth.defaultAccount = eth.accounts[1] // Choose whichever account you want here.
"0x35d68fb24df0e54d44e6cc32f75f1cc891f57811" // It'll echo back the address you chose.
> eth.getBalance(eth.defaultAccount, 'latest')
5.000129328647354980468e+19
> var expiration = eth.getBlock('latest').timestamp + 600; // Expire in 10 minutes.
undefined
> loadScript('coinlock.js') // Might have to supply a different path, but you get the idea.
Everything looks in order.
Creating a lock that expires 2015-09-11 18:29:00
Unlock account 35d68fb24df0e54d44e6cc32f75f1cc891f57811
Passphrase: 
Contract deployment tx: 0x... // Yours won't be truncated.
Waiting 12 blocks to ensure we aren't on a fork.
true
> 12 more blocks...
11 more blocks...
10 more blocks...
9 more blocks...
8 more blocks...
7 more blocks...
6 more blocks...
5 more blocks...
4 more blocks...
3 more blocks...
2 more blocks...
1 more blocks...
0 more blocks...
Contract address is 0xc027...
DO NOT LOSE THIS ADDRESS! // Or you'll lose access to your coins!
Setting lock expiration to 2015-09-11 18:29:00
Done. Run 'redeem.js' after the expiration to get your ether back.
> eth.sendTransaction({from: eth.defaultAccount, to: "0xc027...", value: 1000000000000000000})
"0x..." // Loaded up 1 ether into lock contract.

At this point you can try to redeem the lock. It won't send your coins until the latest block timestamp has passed the expiration timestamp you set earlier. When you finally redeem your coins, it should look something like the example below.

> eth.defaultAccount = eth.accounts[1] // Has to be the account that created the lock.
"0x35d68fb24df0e54d44e6cc32f75f1cc891f57811"
> var address="0xc027...";
undefined
> loadScript('./redeem.js')
Everything looks in order.
Retrieving coins at 2015-09-11 18:29:00
Unlock account 35d68fb24df0e54d44e6cc32f75f1cc891f57811
Passphrase: 
Redemption tx is 0x...
true
> eth.getBalance(eth.defaultAccount, 'latest')
5.000127707697354980468e+19

Feel free to open an issue if you have any questions or concerns.

coinlock's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.