Skip to main content

Submitting transactions

Advanced
Bitcoin
Tutorial

Overview

To submit transactions to the Bitcoin network, the Bitcoin integration API exposes the following method:

  • bitcoin_send_transaction: Submits a transaction to the Bitcoin network.

Sending transactions

To send transactions to the Bitcoin network, make a call to the bitcoin_send_transaction Bitcoin API method. You can create a function in your canister to call this method such as:

 type ManagementCanisterActor = actor {
bitcoin_send_transaction : SendTransactionRequest -> async ();
};

let management_canister_actor : ManagementCanisterActor = actor("aaaaa-aa");

public func send_transaction(network : Network, transaction : [Nat8]) : async () {
let transaction_fee =
SEND_TRANSACTION_BASE_COST_CYCLES + transaction.size() * SEND_TRANSACTION_COST_CYCLES_PER_BYTE;

ExperimentalCycles.add(transaction_fee);
await management_canister_actor.bitcoin_send_transaction({
network;
transaction;
})
};

Then make a call to this canister's function with the command:

dfx canister call CANISTER_NAME send '(record { destination_address = "ADDRESS"; amount_in_satoshi = 100000000; })'

Replace CANISTER_NAME with your canister's name and replace ADDRESS with the destination Bitcoin address. Learn more about Bitcoin addresses.

Resources