Have you ever wondered what it takes to build a smart contract financial product on Bitcoin Cash? In the first half of 2019 I joined a small team to build a non-custodial futures contract, or at least try and see what is possible and what is not.
This article will outline my part of the story leading up to the AnyHedge launch in 2020.
Where it started
I wasn't part of the team when the idea was first formalized in March of 2019 and the first draft of a contract was successfully compiled using an early version of Spedn, but I joined soon after to help build the tools required to use the contract.
We worked on our own time and without funding, but the interest from a possible investor at this point was a signal that we were working on what might one day become a profitable company.
Early adopter issues
To build smart contracts on Bitcoin Cash requires an understanding of not only the scripting language, but also transaction signing and protocol structures and limitations.
Not long after I had started working, I discovered that there was no good source of information anywhere. I had to go read Bitcoin (BTC) documentation, which was often wrong due to being updated for BTC, or because BCH had diverged from it. I also had to read and try to understand node upgrade specifications to learn how Bitcoin Cash functioned differently, which only lists the changes and frequently referred back to "same as before", with no references to any sources of what was before.
Working with poor documentation is difficult and unproductive, so I wrote the BUIP121 proposal to Bitcoin Unlimited to help build better public documentation for developers who need to interact with the protocol.
While not perfect today, the work done by Bitcoin Unlimited and Bitcoin Verde has given new developers access to better documentation than we had before.
In the months after I joined we each did our best to make progress, but work was slow and intermittent for various reasons. With the help of our potential investors, I was able to go to Townsville ahead of the Bitcoin Cash City Conference and meet up with the team.
At this point, work really took off and in a matter of weeks we went from having a non-functional draft contract, to successfully funding and redeeming the first AnyHedge contract on-chain.
During the conference in September 2019 we held our first demonstration to potential partners and investors and got our first verbal agreement to integrate with an exchange.
It was hacky. It was blunt. It was messy.
The tools we relied on were unfinished and buggy (as evident by 0.1.x version numbers), but with the help of the fantastic Meep transaction debugger from the BCHD team we eventually managed to go from idea, to proof of concept.
Unreliable REST APIs
We built our tooling on the best-known and best documented developer stack that was available to us, the BitBox SDK and related REST API. It served us well in the prototyping phase, but at the end of 2019 it became apparent to us that it was not sustainable to build financial commercial projects on public free infrastructure.
We looked at many alternatives and eventually settled on using Electrum servers as our backend. The Electrum protocol is not perfect, but since it powers the Electron Cash wallet and has multiple server software it is likely to stay maintained going forward.
Finding good tools to interact with the servers turned out to be problematic, though. Most were no longer maintained, or didn't support the features we needed. We built the electrum-cash library that supports all features of the electrum protocol, including encryption, websockets and automated version negotiation.
The electrum-cash library is now used by many actors in the ecosystem, for example flipstarter, mainnet, fullstack and cashscript. We have also made a commitment to financially support the infrastructure we depend on and have a public sponsorships that will grow in size as we grow in revenue.
Who do you partner with if you're the first?
The AnyHedge contract has two contract parties, and an oracle they trust to provide pricing information. From the start, we wanted to use a 3rd party oracle, but what do you do when you're the first one to the scene and there's no one else to partner up with?
We talked with many companies such as Bitpay, Chainlink, Coin Dance, Blockchair and CoinGecko, who either have a good source for price data, or provide services using price data. Unfortunately due to different infrastructure needs from ETH and the fact that BCH smart contracts were unproven in the market, it was not yet compelling enough for them to invest resources in a BCH oracle.
We then tried to collaborate with other developers to set up standards and documentation so that if we had to build it ourselves, we would at least be building something that is reusable and valuable to others, but this effort also fell flat as there was no one else building smart contracts that had a usecase for the kind of oracle that we needed.
We then built a price-oracle library and an oracle service that is publicly available to other builders in the Bitcoin Cash ecosystem. In the future, we will re-engage the discussion and try to find external partners to run the price oracle services.
Having met with our potential investors we felt we had good alignment and we worked together to build a businessplan, shareholders agreement and other paperwork.
After some months it turned out that due to changes in expectations the requirements from the investors was changed and we had a falling out.
It was really painful to go back to the uncertainty with regards to funding at this time as we didn't know if we'd ever have another chance.
At this point, we had been self-funded for 9 months already and we had to set up plans for how far we were willing to go before deeming the project a failure.
New year, new troubles
The Infrastructure Funding Plan
At the start of 2020, Jiang Zhuoer announced his intent to fund infrastructure via coinbase reward. The proposal had some initial positive reception as it was easy for most people to see the good that extra funding could accomplish, but after a few weeks it was clear that the costs of the IFP were unacceptable.
Despite the concerns raised, though, Bitcoin ABC officially added a version of the IFP to their codebase and set it to be miner-activated ahead of the may upgrade.
As none of us on the team wanted to work on a coin we didn't believe in, we now had to make a choice - either disband, or solve the underlying funding problem..
Seeing that the Bitcoin Cash ecosystem was at risk, and that we had built our product on it, the company shifted all available resources to address the funding problem.
We took some time to listen and found out that one of the major problems was the free-rider or unfairness aspect of voluntary donation, where some miners who have supported the ecosystem financially were unhappy that others have benefitted without supporting anything at all.
After a month of working non-stop, Flipstarter was unveiled as a non-custodial assurance contract fundraising tool, and later on successfully raised $500k to fund infrastructure.
While we spent almost two months working full-time on Flipstarter, it was a community effort and with the help of all who contributed to it, a wide range of projects has already raised more than 5,000 BCH (~$1.2 million USD at the time of campaign completion).
Bitcoin Cash Node
While I was focusing almost exclusively on coding for Flipstarter, other members of the team also helped with the set up of the first fork of Bitcoin ABC as a contingency plan and drop-in replacement for miners who wanted to oppose the IFP.
A serious, responsible company
After having shown that the IFP wasn't the only possible way to resolve funding, we returned to building on AnyHedge and by mid-2020 we were once again moving forward at a respectable pace and making good progress.
We released the AnyHedge Whitepaper, outlining the contract structure and explaining how you can trade volatility risk to achieve value stability without leaving the Bitcoin Cash ecosystem.
We completed a collaboration with Karol Trzeszczkowski and released a numerical analysis of the AnyHedge smart contract.
To help traders better understand the contract behaviour, we built and released an online contract simulator.
During the time we worked on Flipstarter and BCHN we built new relations and we found ourselves in contact with new investors. Having shown our ability to execute on the plans we had laid forward, we secured our first round of investment of over 1 million USD.
Can we cancel 2020, please?
We were finally back to building on AnyHedge again. Our automated settlement service was taking shape nicely and just as we were starting to focus on the exchange integration, we again got the rug pulled out from under us without warning.
In July 2020, Bitcoin ABC decided to shock the ecosystem by announcing their own DAA replacement, despite existing ecosystem-wide collaboration and convergence on a different algorithm. The Grasberg DAA would drastically change the expectations on block production with its past-drift correction.
Having built our oracle and contract infrastructure on the now decades old expectation that Bitcoin, on average, produces one block per 10 minutes we found ourself scrambling to emergency meetings to understand the implications.
Upon realizing that it would likely result in a redesign of our oracle and contract structures, and would delay us to market by months, we decided that this was not acceptable and issued a joint statement with our partners on the matter.
I reached out directly to Amaury at Bitcoin ABC and explained that this would have serious and damaging implications for us. He told me that it would be best if I adapted to the new rule, stating that it was necessary to change the emissions schedule (to make it predictable) in order to demonstrate a commitment to not changing it.
Seeing as almost all people we could reach in the ecosystem were discontent with both the Grasberg changes to established expectations, and the reckless and frankly disrespectful way that Bitcoin ABC had pushed out the DAA change, we chose to collaborate with and help produce an ecosystem-wide joint statement in favor of the aserti3-2d DAA.
Return of the IFP
Despite the previous hard position, in just a handful of weeks Bitcoin ABC backed down with regards to the Grasberg DAA, but in a tantrum instead laid down an ultimatum to implement the IFP. This version came with entirely new numbers and again involved unknown entities that were to be in control the funds and clearly stated that it was "not an invitation to debate".
Talking with people made it obvious that this was the straw that broke the camels back, and we would see Bitcoin ABC force a split of the network in the coming hardfork.
As a company trying to build a product, we need a userbase to sell our product to. If we continue splitting our network effect over and over there'll be no customers left for us, and we will have failed.
Thankfully, we had already demonstrated via Flipstarter that there were viable alternatives and while we still spent a lot of time building relationships and keeping people informed about the possible outcomes, it wasn't as bad as the first time.
Summary of the journey along the road to AnyHedge
We are now in the end of 2020, and what I estimated would be a handful of months of work ended up taking almost two years. It shouldn't have been this difficult and the lack of developer resources and developer infrastructure has likely been a significant contributor to the current price of Bitcoin Cash.
The good part is that a lot of the problems we encountered no longer exist - the smart contract tooling is getting mature, the documentation is getting better, infrastructure is getting funded and once AnyHedge demonstrates that there is profitable opportunity to be had building non-custodial financial products I expect new teams and companies to enter the space and grow together with us.
As for the product itself we're over the finish line and AnyHedge will soon go out of beta and launch with the Detoken non-custodial exchange.
Without you Bitcoin Cash might have failed this year, just like Bitcoin Core it would also have been captured by a dev team gone rogue.
Thanks to you they failed and it came out stronger than ever with legendary innovations like flipstarter and great new client/collaborations like BCHN.
Big fat thank you Jonathan for everything you did this year