Skip to main content

Generating a Bitcoin address

Advanced
Bitcoin

Overview

A Bitcoin address is a hash value. There are currently two types of Bitcoin addresses: P2SH and P2PKH. An address's full public key cannot be provided when sending transactions, so to redeem transactions sent to your Bitcoin address, you must provide both the transaction signature and the public key used to sign the transaction.

To submit and receive Bitcoin transactions in a canister, you need to generate a Bitcoin address for that canister.

Currently, the ecdsa_public_key API supports generating P2PKH addresses.

Generating a P2PKH address

To generate a P2PKH address for a canister, make a call to the ecdsa_public_key_api:


/// Returns the P2PKH address of this canister at a specific derivation path.
public func get_p2pkh_address() : async BitcoinAddress {
await BitcoinWallet.get_p2pkh_address(NETWORK, KEY_NAME, DERIVATION_PATH)
};

Learn more about Bitcoin addresses.

Learn more about the ecdsa_public_key API.

Bitcoin addresses associated with Internet Identity

By default, your Internet Identity will have a Bitcoin address that can be used to send and recieve BTC. You can view this address by logging into the NNS frontend dapp with your Internet Identity.

Next steps

You can use this address to make Bitcoin transactions from your canister.

Learn how to sign Bitcoin transactions.