Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Bitcoin Cash Smart contracts
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.
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.
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:
- 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 (...)
Bitcoin Cash Smart contract was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.