Skip to main content

Installation

Magic interacts with the Bitcoin blockchain via Magic’s extension NPM package @magic-ext/bitcoin.
NOTEBitcoin support requires @magic-ext/bitcoin v29.0.0 or higher. Bitcoin keys are held in Magic’s TEE, and the signing API changed in v29.0.0. Earlier versions are no longer supported.

Initialization

JavaScript
Magic issues native SegWit (bech32) addresses. Wallets on mainnet are prefixed with bc1, and wallets on testnet are prefixed with tb1. Each network has its own wallet, so a user’s testnet address is not the same as their mainnet address.

Common Methods

Get Public Address

Retrieves the user’s Bitcoin address for the network the extension is configured with.
JavaScript

Sign Transaction

Signs a Bitcoin transaction inside Magic’s TEE and resolves with a broadcast-ready transaction. You supply fully-formed inputs (the UTXOs to spend) and outputs. Coin selection, fees, and change are your responsibility — Magic signs exactly what you pass. The fee is the difference between the total input value and the total output value, so any amount you do not send back to your own address as change is paid to miners. Magic does not broadcast the transaction. Submit the returned signedTransaction to the network yourself via your Bitcoin node or a broadcast API. Arguments
  • inputs (Array): The UTXOs to spend. Each input requires:
    • txid (String): The transaction ID of the transaction that created the UTXO
    • tx_num (Number): The output index (vout) of the UTXO within that transaction
    • value (Number): The value of the UTXO in BTC, not satoshis. This is required — the TEE needs each input’s value to compute its SegWit (BIP143) sighash
    • address (String, optional): The address the UTXO is locked to
  • outputs (Array): The outputs to create. Each output requires:
    • address (String): The recipient address
    • value (Number): The amount to send in BTC, not satoshis
Returns
  • Promise<BitcoinSignedTransaction>
    • signedTransaction (String): The fully-signed, broadcast-ready transaction as hex
    • transactionHash (String): The transaction hash (txid)
If you’re using TypeScript, @magic-ext/bitcoin exports these types directly: BitcoinTransactionInput, BitcoinTransactionOutput, BitcoinSignedTransaction, and BitcoinConfig.
JavaScript

Reveal Private Key

Displays an iframe revealing the user’s Bitcoin private key. See Key Export for more detail.
JavaScript

Resources