Creating a Time-Locked Bitcoin Vault
Last updated
Last updated
Note: This section is a concept and currently under development. The content here will be corrected. For a better view it is recommended to study mirror signature.
A developer wants to:
Lock BTC on the Bitcoin network.
Mirror the locked BTC as mirrorBTC on the Kaon network.
Create a smart contract that enforces a time-locked covenant using mirrorBTC.
Use a voucher to represent the mirroring event and track the locked BTC.
Redeem the mirrorBTC back to BTC through a peg-out process after the time-lock expires.
Install and Configure Bitcoin Core
Install Bitcoin Core
Download and install Bitcoin Core from the official website:
Configure Bitcoin Core
Edit the bitcoin.conf
file to enable RPC and set appropriate settings.
Install and Configure Kaon Node
Clone the Kaon Repository
Build Kaon from Source
Follow the instructions in the README.md
to build Kaon.
Run Kaon Node
Configure Kaon Node
Edit the kaon.conf
file with necessary settings.
Set Up MetaMask with Kaon Testnet
Install MetaMask
Add Kaon Testnet Network
Network Name: Kaon Testnet
New RPC URL: https://testnet.kaon.one
Chain ID: 11989
Currency Symbol: KAON
Block Explorer URL: https://explorer.testnet.kaon.one
Request a Peg-In Address
Use the Kaon CLI or API to request a peg-in address.
Example Output:
Send BTC to the Peg-In Address
Use your Bitcoin wallet or bitcoin-cli
to send BTC to the provided address.
Wait for Transaction Confirmation
Wait for at least 6 confirmations on the Bitcoin network to ensure the transaction is securely recorded.
Kaon Network Detection
Kaon's sMPC participants monitor the Bitcoin network. Once they detect and verify your transaction:
mirrorBTC is minted on the Kaon network.
Voucher NFT is issued representing the peg-in event.
Verify Receipt of mirrorBTC
Check your MetaMask wallet on the Kaon Testnet to confirm the mirrorBTC balance.
Write the Solidity Smart Contract
Create a new file TimeLockedVault.sol
in Remix IDE.
Compile the Contract
Set the compiler version to 0.8.0
or compatible.
Ensure there are no compilation errors.
Deploy the Contract
Environment: Injected Web3 (MetaMask).
Contract: TimeLockedVault
.
Constructor Parameters:
mirrorBTC Address: Input the mirrorBTC token contract address.
releaseTime: Unix timestamp of when the funds can be withdrawn (e.g., block.timestamp + 86400
for 24 hours later).
Deploy: Confirm the transaction in MetaMask.
Add mirrorBTC Token to MetaMask
Token Contract Address: Add the mirrorBTC token address to MetaMask to see your balance.
Deposit mirrorBTC into the Contract
Before depositing, you need to approve the contract to spend your mirrorBTC.
Approve Transfer:
Execute Deposit:
Call the deposit
function from the deployed contract in Remix:
Amount: The amount of mirrorBTC you want to lock.
Confirm: Approve the transaction in MetaMask.
Verify the Deposit
Call the mirrorBTCBalance
function to ensure the funds are deposited.
Alternatively, check the contract's balance in MetaMask or via the Kaon block explorer.
Attempt Early Withdrawal (Should Fail)
Try calling the withdraw
function before releaseTime
.
The transaction should revert with the error: "Current time is before release time"
.
Wait Until Release Time
Wait until the current block timestamp is equal to or greater than releaseTime
.
You can simulate time passage on a local blockchain, but on the testnet, you need to wait in real-time.
Withdraw mirrorBTC after Time-Lock Expires
Call the withdraw
function from the contract.
Confirm the transaction in MetaMask.
The mirrorBTC is transferred back to your wallet.
Initiate Peg-Out Request
Send your mirrorBTC to the designated peg-out address or smart contract provided by Kaon.
Peg-Out Contract Address: Obtain from Kaon's documentation or via:
Transfer mirrorBTC:
In MetaMask or via a script:
Burn mirrorBTC and Prepare BTC Transaction
The peg-out contract burns the mirrorBTC to prevent double-spending.
The sMPC group prepares a Bitcoin transaction to send BTC back to your Bitcoin address.
Provide Your Bitcoin Address
If required, provide your Bitcoin address to the peg-out contract during the transaction or via an interface.
sMPC Group Signs the Transaction
The transaction is securely signed using Threshold Signature Scheme (TSS) by the sMPC participants.
Broadcast the Transaction to the Bitcoin Network
The signed transaction is broadcasted to the Bitcoin network by the validators.
Wait for Confirmation
Monitor the transaction on a Bitcoin block explorer.
Wait for at least 6 confirmations to ensure the transaction is secure.
Receive BTC
The BTC is deposited into your provided Bitcoin address.
Voucher Redemption
The voucher NFT associated with the mirrorBTC is marked as redeemed.
You can verify this by checking the voucher's status in an NFT explorer or your wallet.
Check Transaction Histories
Bitcoin Network:
Kaon Network:
Verify Voucher Status
View Voucher Details:
Use an NFT-compatible wallet or an explorer that supports Kaon NFTs.
Check the metadata to confirm the voucher is marked as redeemed.
mirrorBTC is a token on the Kaon network that represents BTC locked on the Bitcoin network. It allows users to leverage their BTC within the Kaon ecosystem, enabling interactions with EVM-compatible smart contracts and decentralized applications.
Liquidity: Utilize BTC liquidity in DeFi applications on Kaon.
Interoperability: Interact with Ethereum-based tools while holding BTC value.
Security: Benefit from Kaon's security mechanisms without relying on centralized bridges.
A covenant imposes conditions or restrictions on how and when funds can be spent in the future, enhancing security and enabling complex financial instruments.
In the TimeLockedVault
contract, the covenant is enforced through a time lock:
This line ensures that the withdraw
function can only be executed after the specified releaseTime
.
A voucher in Kaon is an NFT that represents a specific peg-in event. It tracks the locked BTC and provides proof of ownership and status of the mirrored assets.
Via Wallet: Use an NFT-compatible wallet that supports the Kaon network to view your vouchers.
Metadata: Vouchers contain metadata such as tokenId
, amount
, status
, and related transactions
.
Example Voucher Metadata
Before a smart contract can transfer tokens on your behalf, you must grant it permission:
Use the transferFrom
method to move tokens from the user's address to the contract:
Checking mirrorBTC Balance
Always perform operations on the Kaon Testnet to familiarize yourself with the processes and avoid potential loss of funds.
Use secure wallets and consider hardware wallets for storing private keys.
Never share your private keys or seed phrases.
Regularly check Kaon's official channels for updates:
Ensure that you set sufficient gas limits and gas prices for transactions on the Kaon network to avoid failures or delays.
Kaon Transactions: Use the Kaon block explorer to monitor the status of your mirrorBTC and smart contract transactions.
Bitcoin Transactions: Use a Bitcoin block explorer to track your BTC transactions during peg-in and peg-out.
By completing this use case, you have:
Successfully mirrorBTC to mirrorBTC through a peg-in process.
Created and interacted with a time-locked vault smart contract utilizing covenants.
Managed and redeemed a voucher representing your mirrored assets.
Performed a peg-out to convert mirrorBTC back to BTC on the Bitcoin network.
This practical example demonstrates how developers can leverage Kaon's unique features to build secure, decentralized financial applications that bridge the Bitcoin and Ethereum ecosystems without relying on centralized intermediaries.
Download from .
Use a Bitcoin block explorer like or to view your BTC transactions.
Use the Kaon block explorer at to view your mirrorBTC transactions.
Website:
Documentation:
GitHub:
Kaon GitHub Repository:
Kaon Documentation:
Remix IDE:
Solidity Documentation:
MetaMask:
Bitcoin Core: