LogoLogo
Threshold WebsitetBTC v2 DocsTACo Docs
  • What is the Threshold Network?
  • THRESHOLD DASHBOARD
    • tBTC Minting Walkthrough
  • Applications
    • tBTC Bitcoin Bridge
      • Fees
      • Wallet Generation
      • Wallet Signing
      • The Path to Permissionlessness
      • Sweeping
      • Coverage Pool
    • Threshold USD
      • Overview of thUSD
      • Borrowing
      • Stability Pool and Liquidations
      • Redemptions and thUSD Price Stability
      • Recovery Mode
      • Bootstrapping
        • Initial Protocol Loan
      • B. Protocol
      • thUSD on Build on Bitcoin (BOB)
        • Connecting to BOB Network
        • Bridging Collateral to BOB Network
        • Opening Collateral Vaults and Minting thUSD
  • Governance
    • Threshold DAO
      • 🗳️Governance Process
      • 🙋‍♀️Guilds
      • 💰Threshold Multisigs
      • Threshold DAO Rules
    • Vote Delegation
      • Liquid Token Delegation
  • Staking & Running a Node
    • tBTC v2 Node Setup
      • Operator Account
      • Application Authorization & Operator Registration
      • Network Configuration
      • Data Storage
      • Installation
        • Docker Installation
        • Binary Installation
      • Updating tBTC v2 Node
      • Advanced Options
        • Alternatives to Dashboard
        • Logging
        • Config File
        • CLI Options
        • Client Info
      • Frequently Asked Questions
      • Sepolia Testnet
        • Testnet tBTC v2 node Setup
    • tBTC Beta Stakers Program
  • App Development
    • DAO Contracts
      • DAO Contracts API
        • BaseTokenholderGovernor
        • Checkpoints
        • GovernorParameters
        • IApplication
        • ILegacyTokenStaking
        • IStaking
        • IVotesHistory
        • KeepStake
        • PercentUtils
        • ProxyAdminWithDeputy
        • SafeTUpgradeable
        • StakerGovernor
        • StakerGovernorVotes
        • T
        • TokenholderGovernor
        • TokenholderGovernorVotes
        • TokenStaking
        • VendingMachine
    • Random Beacon
      • Random Beacon API
        • AltBn128
        • BeaconAuthorization
        • BeaconDkg
        • BeaconDkgValidator
        • BeaconInactivity
        • BLS
        • BytesLib
        • Callback
        • Governable
        • Groups
        • IRandomBeacon
        • IRandomBeaconConsumer
        • ModUtils
        • RandomBeacon
        • RandomBeaconChaosnet
        • RandomBeaconGovernance
        • Reimbursable
        • ReimbursementPool
        • Relay
    • tBTC
      • tBTC SDK
        • Quickstart
        • Architecture
        • Guides
          • Initialize SDK
            • Ethereum and Bitcoin mainnet
            • Ethereum and Bitcoin testnet
            • Crosschain
            • Custom mode
          • Deposit and mint
          • Unmint and redeem
        • API Reference
      • tBTC Contracts API
        • Bridge API
          • Bank
          • BitcoinTx
          • Bridge
          • BridgeGovernance
          • BridgeGovernanceParameters
          • BridgeState
          • Deposit
          • DepositSweep
          • DonationVault
          • EcdsaLib
          • Fraud
          • GovernanceUtils
          • Heartbeat
          • IReceiveBalanceApproval
          • IRelay
          • IVault
          • L2TBTC
          • L2WormholeGateway
          • LightRelay
          • LightRelayMaintainerProxy
          • MaintainerProxy
          • MovingFunds
          • Redemption
          • TBTC
          • TBTCOptimisticMinting
          • TBTCVault
          • VendingMachine
          • VendingMachineV2
          • VendingMachineV3
          • WalletCoordinator
          • Wallets
        • ECDSA API
          • EcdsaAuthorization
          • EcdsaDkg
          • EcdsaDkgValidator
          • EcdsaInactivity
          • IWalletOwner
          • IWalletRegistry
          • WalletRegistry
          • WalletRegistryGovernance
          • Wallets
  • Resources
    • T Token
    • Contract Addresses
      • Mainnet
        • Threshold DAO
        • tBTC
        • thUSD
        • Legacy
      • Görli Testnet
      • Sepolia Testnet
    • Security Audits
    • tBTC Pools
    • Upgrade NU & KEEP to T
    • Contribution
    • Security
    • Brand Assets
    • Links
Powered by GitBook
On this page
  • Initialize the SDK
  • Initiate the deposit
  • Make the Bitcoin deposit transaction
  • Initiate minting

Was this helpful?

Export as PDF
  1. App Development
  2. tBTC
  3. tBTC SDK
  4. Guides

Deposit and mint

The main feature of the tBTC bridge is depositing BTC and using it to mint the ERC-20 TBTC token. This guide explains how to perform this process using the SDK.

Initialize the SDK

First, initialize the SDK, as described in the Initialize SDK guide.

Initiate the deposit

Once the SDK is initialized, you can initiate the deposit and get their Bitcoin address in the following way:

import { TBTC } from "@keep-network/tbtc-v2.ts"

// Initialized SDK.
const sdk: TBTC

// Set the P2WPKH/P2PKH Bitcoin recovery address. It can be used to recover
// deposited BTC in case something exceptional happens.
const bitcoinRecoveryAddress: string = "..."

// Initiate the deposit.
const deposit = await sdk.deposits.initiateDeposit(bitcoinRecoveryAddress)

// Take the Bitcoin deposit address. BTC must be sent here.
const bitcoinDepositAddress = await deposit.getBitcoinAddress()

Make the Bitcoin deposit transaction

The next step is doing the actual Bitcoin deposit transaction to the deposit address. There are two possible ways to do so:

  • Recommended: Use an external Bitcoin wallet

  • Non-recommended: Use the experimental SDK DepositFunding component. This code is used for testing purposes and is not safe for production use!

Initiate minting

Once the Bitcoin deposit transaction is done, minting can be initiated. This can be done using the initiateMinting method exposed by the Deposit class. This method has two modes:

  • Automatic: Automatically detect the latest funding UTXO and use it to initiate minting. This mode is the default one that should be used when a single Bitcoin deposit transaction has been made.

  • Manual: Take a funding UTXO as a parameter and use it to initiate minting. This mode can be useful when multiple Bitcoin deposit transactions target the same deposit address.

Here is an example of both:

// Initiate minting using latest funding UTXO. Returns hash of the
// initiate minting transaction. Can throw an error if there are no
// Bitcoin funding transactions targeting this deposit address. 
// In that case, consider retrying after a delay.
const txHash = await deposit.initiateMinting()
// Detect funding UTXOs manually. There can be more than one.
await fundingUTXOs = await deposit.detectFunding()

// Initiate minting using one of the funding UTXOs. Returns hash of the
// initiate minting transaction.
const txHash = await deposit.initiateMinting(fundingUTXOs[0])
PreviousCustom modeNextUnmint and redeem

Last updated 9 months ago

Was this helpful?