paint-brush
Bitcoin Cash Smart contractby@sriharikapu
171 reads

Bitcoin Cash Smart contract

by Aaron SwartzOctober 28th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Today I want to speak something interesting. It's about Smart contracts on top of the Bitcoin cash Blockchain. For those of you who don't know what is Bitcoin cash. Bitcoin cash is a hard fork of the Bitcoin Blockchain in which people spoke about scalability and transaction fee, the volume of transactions. i.e in simple words Bitcoin, the community decided to create a new blockchain which can accommodate a larger size of blocks and less transaction fee on the transactions. Apart from all that instant transaction is there to blow up your mind, I mean practically no that instant but its really better than bitcoin transaction speed. If you don't know what is a fork, let me help you to understand it, A hard fork is a permanent divergence from the previous version of the Blockchain, and nodes running previous versions will no longer be accepted by the newest version.

Coin Mentioned

Mention Thumbnail
featured image - Bitcoin Cash Smart contract
Aaron Swartz HackerNoon profile picture

Today I want to speak something interesting. It's about Smart contracts on top of the Bitcoin cash Blockchain. For those of you who don't know what is Bitcoin cash. Bitcoin cash is a hard fork of the Bitcoin Blockchain in which people spoke about scalability and transaction fee, the volume of transactions. i.e in simple words Bitcoin, the community decided to create a new blockchain which can accommodate a larger size of blocks and less transaction fee on the transactions. Apart from all that instant transaction is there to blow up your mind, I mean practically no that instant but its really better than bitcoin transaction speed. If you don't know what is a fork, let me help you to understand it, A hard fork is a permanent divergence from the previous version of the Blockchain, and nodes running previous versions will no longer be accepted by the newest version.

hard fork

What's so special about Bitcoin cash?

There isn’t a much of a difference between Bitcoin and Bitcoin cash. Both of them are built to serve the same purpose “Peer to Peer Digital cash”. Below are some of the interesting facts about the Bitcoin and Bitcoin Cash.

Bitcoin vs Bitcoin Cash

Can we create smart contracts on Bitcoin Cash?

Yes! we can write smart contracts on Bitcoin Cash. Well, let me tell you what are the difficulties we gonna face in writing the Bitcoin Cash smart contracts.

  • Community & Developers working on writing Bitcoin cash is in the early phase. So, Be prepared you to need to do your homework ready by yourself not a lot of people are there as of now to help you on your coding the Bitcoin Cash contracts.
  • We are going to use a high-level language named “Spedn” for coding our smart contracts.
  • Haskell is used for testing Bitcoin cash smart contracts.

Let us code our first Bitcoin cash smart contract:

  1. Install Haskell Toolkit on your device.

    $ curl -sSL https://get.haskellstack.org/ | sh

2. Create a new project:

$ stack new my-project$ cd my-project$ stack setup$ stack build$ stack exec my-project-exe

3. To launch run :

$ stack ghci

4. For a list of Haskell commands:

$ stack 

5. Clone the “Spedn”

$ git clone https://github.com/sriharikapu/Spedn.git or $ git clone https://bitbucket.org/o-studio/spedn.git

6. Build “Spedn”

$ cd spedn/spedn$ stack install

7. Create a directory for a smart contract:

$ mkdir samplecontract$ touch ExiringTip.spedn$ nano ExiringTip.spedn

8. Let's consider a case for writing our smart contract:

Let’s assume Alice want to tip a waiter Bob with a paper wallet but she wants to be sure that the coin will not get lost due to Bob losing the paper.

This contract locks a coin in such a way that Bob can redeem it at any time but if he didn’t do so in 7 days then Alice can get it back.

contract ExpiringTip(Ripemd160 alice, Ripemd160 bob) {    challenge receive(Sig sig, PubKey pubKey) {        verify hash160(pubKey) == bob;        verify checkSig(sig, pubKey);    }    challenge revoke(Sig sig, PubKey pubKey) {        verify checkSequence(7d);        verify hash160(pubKey) == alice;        verify checkSig(sig, pubKey);    }     challenge cancel(Sig Sig) {        verify checkSequence(8b);        verify checkSig(Sig, PubKey);    }}

9. Compile your smart contract:

$ spedn compile -c mycontract.spedn

10. Compiled contract template:

<alice> <bob> 2 PICK TRUE EQUAL IF 3 PICK HASH160 OVER EQUALVERIFY (...)

Open source