Wrapped BTC Contract
This page explains how to create a simple wrapped Bitcoin implementation using the Glittr SDK. The example demonstrates creating a contract that allows users to mint wrapped BTC tokens at a 1:1 ratio.
1. Setup and Configuration
import {
Account,
addFeeToTx,
BitcoinUTXO,
BlockTxTuple,
electrumFetchNonGlittrUtxos,
GlittrSDK,
OpReturnMessage,
Output,
txBuilder
} from "@glittr-sdk/sdk";
const NETWORK = "regtest";
const client = new GlittrSDK({
network: NETWORK,
apiKey: <your api key here>,
glittrApi: "https://devnet-core-api.glittr.fi",
electrumApi: "https://devnet-electrum.glittr.fi"
});First, we import the necessary components from the Glittr SDK and initialize the client with the appropriate network settings. In this case, we're using the regtest network for development purposes.
2. Account Setup
We create two accounts:
creatorAccount: The account that will create and manage the contractminterAccount: The account that will mint wrapped BTC tokens
3. Creating the Contract
The contract creation function sets up:
A maximum supply of 21 million (matching Bitcoin's cap)
8 decimal places of divisibility (matching Bitcoin)
A 1:1 exchange ratio between BTC and the wrapped token
No time restrictions on minting/burning
4. Minting Wrapped BTC
The minting function:
References the existing contract
Creates a mint transaction
Sends Bitcoin to the creator's address
Receives wrapped BTC tokens in return
5. Checking Asset Details
This utility function allows you to check the details of an asset by its transaction ID and output index.
Key Concepts
1:1 Backing: Each wrapped BTC token is backed by an equivalent amount of Bitcoin.
Supply Cap: The contract matches Bitcoin's supply cap of 21 million.
Divisibility: The wrapped token maintains the same 8 decimal places as Bitcoin.
Purchase/Burn: Users can mint tokens by sending BTC and burn tokens to receive BTC back.
This implementation provides a simple way to create wrapped Bitcoin tokens that maintain a 1:1 peg with actual Bitcoin, allowing for easier integration with other Glittr contracts and applications.
Usage Flow
Initialize the SDK and accounts
Create the wrapped BTC contract
Mint wrapped BTC tokens
Check asset details
Full Code Example
Last updated