Skip to main content

Signing transactions

Advanced
Bitcoin
Tutorial

Before a transaction can be sent to the Bitcoin network, each input must be signed.

Threshold ECDSA

Canisters can sign transactions with threshold ECDSA through the sign_with_ecdsa method.

To test canisters locally that use the following code snippets, you will need to enable local Bitcoin development. To do this, you can either start the local replica with dfx start --enable-bitcoin or you can include the following configuration in the project's dfx.json file:

motoko/basic_bitcoin/dfx.json
loading...

Learn more about dfx.json configuration options.

The following snippet shows a simplified example of how to sign a Bitcoin transaction for the special case where all the inputs are referencing outpoints that are owned by own_address and own_address is a P2PKH address.

motoko/basic_bitcoin/src/basic_bitcoin/src/BitcoinWallet.mo
loading...

Threshold Schnorr

Canisters can sign transactions with threshold Schnorr through the sign_with_schnorr method.

Signing P2TR key path transactions

The following snippet shows a simplified example of how to sign a Bitcoin transaction for the special case where all the inputs are referencing outpoints that are owned by own_address and own_address is a P2TR address.

motoko/basic_bitcoin/src/basic_bitcoin/src/P2tr.mo
loading...

Signing P2TR script path transactions

The following snippet shows a simplified example of how to sign a Bitcoin transaction for the special case where all the inputs are referencing outpoints that are owned by own_address and own_address is a P2TR script path address.

rust/basic_bitcoin/src/basic_bitcoin/src/bitcoin_wallet/p2tr.rs
loading...

Learn more

Learn more about threshold ECDSA.

Learn more about threshold Schnorr.