2020-02-26 13:09:44 -07:00
---
id: dlc
title: Executing A DLC with Bitcoin-S
---
## Executing A Discreet Log Contract (DLC)
## Step 1: Get Bitcoin-S Setup
2021-01-22 13:53:21 -06:00
See the [setup document ](../getting-setup.md ).
2020-02-26 13:09:44 -07:00
2021-01-22 13:53:21 -06:00
### Using the GUI
2020-02-26 13:09:44 -07:00
2021-01-22 13:53:21 -06:00
To first start up the GUI you first need to start your bitcoin-s server and gui with
2020-02-26 13:09:44 -07:00
```bashrc
2021-01-22 13:53:21 -06:00
sbt bundle/run
2020-02-26 13:09:44 -07:00
```
2021-01-22 13:53:21 -06:00
or if your bitcoin-s server is already running, you can run the standalone gui with
2020-02-26 13:09:44 -07:00
```bashrc
2021-01-22 13:53:21 -06:00
sbt gui/run
2020-02-26 13:09:44 -07:00
```
2021-01-22 13:53:21 -06:00
or by following the instructions for building and running the GUI [here ](../getting-setup.md#step-5-setting-up-a-bitcoin-s-server )
2020-02-26 13:09:44 -07:00
2021-01-22 13:53:21 -06:00
## Step 2: Agree On Contract Terms
2020-08-26 12:31:08 -05:00
2021-01-22 13:53:21 -06:00
Both parties must agree on all fields from the table below:
2020-08-26 12:31:08 -05:00
2021-01-22 13:53:21 -06:00
| Field Name | Description |
| :------------: | :------------------------------------------------------: |
| contractInfo | Information about payouts and which oracles to use |
| collateral | Number of sats the initiator is putting up |
| locktime | Locktime of the CETs |
| refundlocktime | Locktime of the Refund Transaction |
| feerate | Fee rate in sats/vbyte |
2020-05-18 19:04:31 -05:00
2021-01-22 13:53:21 -06:00
> Note: if you wish to set up your own oracle for testing, you can do so by checking out our [oracle rpc server](../oracle/oracle-server.md) or [Krystal Bull](https://github.com/benthecarman/krystal-bull)
2020-05-18 19:04:31 -05:00
2021-01-22 13:53:21 -06:00
## Step 3: Set up The DLC
2020-08-25 09:33:05 -06:00
2021-01-22 13:53:21 -06:00
### Using the GUI
2020-05-18 19:04:31 -05:00
2021-01-22 13:53:21 -06:00
If you're a visual learner there is a [video demo ](https://www.youtube.com/watch?v=zy1sL2ndcDg ) that explains this process in detail.
But do note that this demonstrates the old non-adaptor version of DLCs so that the Offer, Accept, Sign protocol is the same, but the contents will be different.
2020-05-18 19:04:31 -05:00
2021-01-22 13:53:21 -06:00
If using a numeric contract and/or multiple oracles, messages can get very large and sometimes even too large to for the application.
To solve this there is an `Export to file` button located under the text box for the messages your wallet will construct.
This can be used to export a DLC message to a file and then the file can be sent to your counter party.
If you receive a file from a counter-party, there is an `Import file` button on every dialog you input a DLC message.
This can be used to import the file of the DLC message from your counter-party.
2020-05-18 19:04:31 -05:00
#### Creating The Offer
Once the terms are agreed to, either party can use the `Offer` button and enter each of the fields from the table above.
#### Accepting The Offer
Upon receiving a DLC Offer from your counter-party, you can use the `Accept` button and paste in the DLC Offer.
#### Signing The DLC
Upon receiving a DLC Accept message from your counter-party, you can use the `Sign` button and paste in the DLC Accept.
#### Adding DLC Signatures To Your Database
Upon receiving a DLC Sign message from your counter-party, add their signatures to your database using the `Add Sigs` button and paste in the message.
After doing so you can get the fully signed funding transaction using the `Get Funding Tx` button. This will return the fully signed serialized transaction.
2021-01-22 13:53:21 -06:00
### Using the CLI
2020-05-18 19:04:31 -05:00
2021-01-22 13:53:21 -06:00
If using a numeric contract and/or multiple oracles, messages can get very large and sometimes even too large to for the application.
To solve this there are RPC calls where you can give a file instead of the entire DLC message.
To output a file you simply just need to pipe the output of a command into a file.
2020-05-18 19:04:31 -05:00
2021-01-22 13:53:21 -06:00
For example:
```bashrc
./app/cli/target/universal/stage/bitcoin-s-cli acceptdlcoffer [offer] > myDLCAccept.txt
```
2020-05-18 19:04:31 -05:00
#### Creating The Offer
2020-02-26 13:09:44 -07:00
Once these terms are agreed to, either party can call on `createdlcoffer` with flags for each of the fields in the table above. For example:
```bashrc
2021-01-22 13:53:21 -06:00
./app/cli/target/universal/stage/bitcoin-s-cli createdlcoffer [contractInfo] [collateral] [feerate] [locktime] [refundlocktime]
2020-02-26 13:09:44 -07:00
```
2020-05-18 19:04:31 -05:00
#### Accepting The Offer
2020-02-26 13:09:44 -07:00
Upon receiving a DLC Offer from your counter-party, the following command will create the serialized accept message:
```bashrc
2021-01-22 13:53:21 -06:00
./app/cli/target/universal/stage/bitcoin-s-cli acceptdlcoffer [offer]
```
or from file:
```bashrc
./app/cli/target/universal/stage/bitcoin-s-cli acceptdlcofferfromfile [filepath]
2020-02-26 13:09:44 -07:00
```
2020-05-18 19:04:31 -05:00
#### Signing The DLC
2020-02-26 13:09:44 -07:00
Upon receiving a DLC Accept message from your counter-party, the following command will generate all of your signatures for this DLC:
```bashrc
2021-01-22 13:53:21 -06:00
./app/cli/target/universal/stage/bitcoin-s-cli signdlc [accept]
```
or from file:
```bashrc
./app/cli/target/universal/stage/bitcoin-s-cli signdlcfromfile [filepath]
2020-02-26 13:09:44 -07:00
```
2021-01-22 13:53:21 -06:00
2020-05-18 19:04:31 -05:00
#### Adding DLC Signatures To Your Database
2020-02-26 13:09:44 -07:00
Upon receiving a DLC Sign message from your counter-party, add their signatures to your database by:
```bashrc
2021-01-22 13:53:21 -06:00
./app/cli/target/universal/stage/bitcoin-s-cli adddlcsigs [sign]
2020-02-26 13:09:44 -07:00
```
2021-01-22 13:53:21 -06:00
or from file:
```bashrc
./app/cli/target/universal/stage/bitcoin-s-cli adddlcsigsfromfile [filepath]
```
#### Getting Funding Transaction
2020-02-26 13:09:44 -07:00
You are now fully setup and can generate the fully signed funding transaction for broadcast using
```bashrc
2021-01-22 13:53:21 -06:00
./app/cli/target/universal/stage/bitcoin-s-cli getdlcfundingtx [contractId]
2020-02-26 13:09:44 -07:00
```
2021-01-22 13:53:21 -06:00
where the `contractId` is in all but the messages other than the DLC Offer message, and is also returned by the `adddlcsigs` command.
Alternatively, you can use the `getdlcs` command to list all of your current DLCs saved in your wallet.
## Step 4: Executing the DLC
### Using the GUI
#### Execute
You can execute the DLC unilaterally with the `Execute` button which will require the oracle signature.
This will return a fully signed Contract Execution Transaction for the event signed by the oracle.
#### Refund
If the `refundlocktime` for the DLC has been reached, you can get the fully-signed refund transaction with the `Refund` button and entering the `contractId` .
2020-02-26 13:09:44 -07:00
2021-01-22 13:53:21 -06:00
### Using the CLI
2020-02-26 13:09:44 -07:00
2020-08-25 09:33:05 -06:00
#### Execute
2020-02-26 13:09:44 -07:00
2020-08-25 09:33:05 -06:00
Upon receiving an oracle signature, you can execute the DLC unilaterally with
2020-02-26 13:09:44 -07:00
```bashrc
2021-01-22 13:53:21 -06:00
./app/cli/target/universal/stage/bitcoin-s-cli executedlc [contractId] [signatureTLVs]
2020-02-26 13:09:44 -07:00
```
2020-08-25 09:33:05 -06:00
which will return fully signed Contract Execution Transaction for the event signed by the oracle.
2020-02-26 13:09:44 -07:00
2020-05-18 19:04:31 -05:00
#### Refund
2020-02-26 13:09:44 -07:00
If the `refundlocktime` for the DLC has been reached, you can get the fully-signed refund transaction with
```bashrc
2021-01-22 13:53:21 -06:00
./app/cli/target/universal/stage/bitcoin-s-cli executedlcrefund [contractId]
2020-02-26 13:09:44 -07:00
```