Guide: Smart Contracts with Bitcoin-S and Krystal Bull

Last week, SuredBits released “Bitcoin-S“. A wallet that lets you create, exchange and execute Discreet Log Contracts. To learn what DLCs are, we recommend our article on the topic.

The whole thing is still relatively complex at the moment, but should become much easier over time. If you don’t want to miss out on the technical possibilities of Bitcoin, you can get an insight into the future of smart contracts on Bitcoin here.

In this guide, we will show you how to set up an Oracle and place a bet on the outcome of an Oracle using a DLC.

Create an Oracle Event

First, let’s look at how to set up an event as an Oracle. For this we will use Krystal Bull by Ben Carman. Download the program here and run it.

At the first start you have to create a new wallet and log in.

The interface is relatively simple. In the overview we see the name of our Oracle, its public key, our staking address and its balance.

In the table below are our events. To create a new announcement we have the choice between“Create Enum Event” and“Create Numeric Event“.

An enum event is an output where one of the answers must be definitely correct. This means, for example, yes/no questions.

A Numeric Event is a numeric output. For example, this would be “What will the price of bitcoin be on 9/21?”.

For our example , we create an Enum event with event name:“Will the bitcoin price be over $30,000 on Wednesday?” (in german)

For the date, we choose the date in question, which in our example is next Wednesday.

We set the possible outputs of the Oracle as “Yes” and“No“.

We confirm the settings with “OK“.

After confirmation we see the event in the overview.

With right click -> View Event we can see the details of the event. Among others also the announcement information.

If you want to publish the event, you can send it to the Suredbits Oracle Explorer by clicking on“Send to Oracle Explorer “. This is purely optional.

If you publish the event, you can find the information about it in the explorer . There you can find the Oracle name, the description, the expiration date and the announcement.

Create DLC

In order to do something with the information that the Oracle provides us with, we need a DLC-compatible wallet. You can download the Suredbits Bitcoin-S wallet here.

After you have downloaded and installed it, you will first create a wallet.

Once you have done that, you will need to send some bitcoin to your wallet. You can get a new receiving address by clicking“Get New Address” on the left side.

The basic process of a DLC

To create a new DLC offer, you first need to click on“Offer“.

In the dialog that opens, we first enter the Oracle Announcement that we have received either from Oracle itself or via the Oracle Explorer. This will automatically fill in the event ID (i.e. the event name).

Via“Outcomes” we can define how many Satoshis we want to win at each outcome. Via“Your Collateral” we define our stake. The fee rate is the fee rate of the execution transaction.

So that your Satoshis are not lured forever in case the Oracle does not respond, you can set a Refund Date.

In this example, we’ll create a bet where I bet 200,000 sat that the bitcoin price will be above $30,000 on Wednesday. The fee rate should be 1sat/vbyte and the bet should expire no later than 7/27/21.

Once you have confirmed the terms of your DLC by clicking“OK“, you will see a long string in the Bitcoin Wallet. This is your DLC offer.

Now you have to communicate this offer to the other participant of the bet.

In the wallet, the other party must click “Accept“.

..enter the DLC offer and confirm the terms of the bet. After that, a string, the“DLC-Accept“, will be displayed again in the Bitcoin Wallet overview. The participant must send this to us again.

Via the“Sign” button we open the signing dialog. In the“DLC-Accept” field we enter the DLC-Accept and confirm with OK.

The status of the event has changed to“Signed” in the overview. The transaction we signed is displayed again as a string, which we send to the other participant again.

The other participant then publishes the transaction via the“Broadcast… ” field.

The published transaction

The published transaction has at least two inputs (here one per participant) and 3 outputs. 2 change outputs and one output in the amount of the bet.

In the wallet itself you will see that your Total Balance has decreased by 200 000 sats.

Publish the result

Once the time has come, the Oracle must publish the result.

In Krystal Bull we open the event, select the result under“Attestations” (in our case “Yes“) and click on“Sign“.

We will be shown an“Attestation“, which we can now either send to the Oracle Explorer, or share with the participants in another way.

If we decide to send it to Oracle Explorer, the attestation will also be displayed on the Explorer page of the event.

Triggering the winnings

Our wallet does not know about this announcement yet. Since we have won the bet, we can now secure our winnings. For this we need the attestation of the Oracle and the Contract ID.

We copy the contract ID of our event with a right click.

… and the attestation of the Oracle.

Then we click on“Execute” in Bitcoin-S, paste both values and confirm with OK.

Because we won, both bets are now sent to us. On the left side you can see your unconfirmed balance.

Our counterparty has lost 200 000 sats and goes empty. He will be informed about this via the overview in the Bitcoin wallet.

On the chain this transaction has only one input and one output.

Notes

In this example, I was both Oracle operator and betting participant. Of course, this is not really an optimal use case for DLCs, as I could have easily published an incorrect result. So currently the Oracle should be a third party who knows nothing about the bet and is trusted by both bettors.

In the future, it will be possible to include different Oracles in the DLC and penalize a false-announcing Oracle using a Stake. You can read more about this in our article.

All in all, this rudimentary example shows an incredible potential where the issue conditions of a transaction can be influenced by the intervention of an unknown party that knows nothing about the two betting participants (!).

Although the effort of these DLCs is currently still enormous, most of this could probably be automated in the future and hidden from the user.

Support us:

If you liked this or any of our other posts please consider supporting us:

Leave a Reply