ckBTC: a canister-issued bitcoin twin token on the IC, 1:1-backed by BTC

You can still get that information from the ckBTC index and archive canisters. The ckBTC minting transactions contain the corresponding Bitcoin txid in their memo field. Just be careful with the byte order which is opposite to what common Bitcoin block explorers expect in their UI. Though this is probably Bitcoin’s fault, not ckBTC’s.

1 Like

Thanks I think I will get the information I need from the block explorers using the txid from the ckbtc minting transactions.

You can derive this from the NNS proposals. The last ckBTC minter upgrade proposal was Proposal: 115473 - IC Dashboard, which states that this release is built from git hash d21c69ba055489905bf801a4aea7145f545c9ff8, so the code at ic/rs/bitcoin/ckbtc/minter at d21c69ba055489905bf801a4aea7145f545c9ff8 · dfinity/ic · GitHub should be the currently deployed version.

After proposal Proposal: 118485 - IC Dashboard passes, it would be ic/rs/bitcoin/ckbtc/minter at 3440457faa3b162d9e1877aaad91ce563c964a25 · dfinity/ic · GitHub.

1 Like

Why has ckBTC not implemented ICRC-2 standards, bro? It can make ckBTC used easily in other canisters (Dapps)

The ICRC-2 design was finalized this week and will be up for an approval vote on the NNS soon. It will be implemented for ckbtc and SNS ledger after that vote happens.

8 Likes

What’s the latest story on working with ckBTC/ICRC locally? Is there any easy solution like dfx pull yet?

2 Likes

What about the ICP ledger?

2 Likes

Is there a way to browse what’s in this directory? How did you know to find the Wasm binary there with its specific name?

Is there a guide to getting ckBTC with the minter setup locally? Is there any kind of development mode on the minter canister locally that allows you to turn off the KYT checks? I have the ckBTC ledger and minter deployed locally, but trying to use the functionality is giving me BUG: upgrade procedure must ensure that the KYT principal is set and now I’m afraid I’ll have to setup an entire KYT local story.

2 Likes

Yeah this little ckBTC example that I’m doing for Azle is getting quite complicated, I don’t understand how a beginner would ever be able to figure this stuff out. There’s got to be a better way to setup these canisters locally, I’m thinking dfx pull is going to do that right?

2 Likes

I accidentally posted this elsewhere, thus I need to write something to distinguish from that message…

I have the kyt canister deployed with the following command:

dfx deploy kyt --specified-id bkyz2-fmaaa-aaaaa-qaaaq-cai --argument '(variant { InitArg = record { minter_id = principal "bd3sg-teaaa-aaaaa-qaaba-cai"; maintainers = vec {}; mode = variant { AcceptAll } } })'

I would expect that in mode AcceptAll that I wouldn’t have to provide an API key, but I’m getting the error:

(
  variant {
    Err = variant {
      TemporarilyUnavailable = "The KYT provider is temporarily unavailable: No valid API keys"
    }
  },
)

This error goes away when I set an empty “” as the api key, but this shouldn’t be necessary IMO.

3 Likes

I’m having a very hard time getting the ckbtc canister deployed with the appropriate did file and arguments. I’m not sure which did file is correct nor why this isn’t working.

Here is my deploy command:

dfx deploy ckbtc --specified-id=be2us-64aaa-aaaaa-qaabq-cai --argument='(variant { Init = record { minting_account = record { owner = principal "bd3sg-teaaa-aaaaa-qaaba-cai" }; transfer_fee = 0 : nat64; token_symbol = "ckBTC"; token_name = "ckBTC"; metadata = vec {}; initial_balances = vec {}; archive_options = record { num_blocks_to_archive = 0 : nat64; trigger_threshold = 0 : nat64; controller_id = principal "aaaaa-aa" } } })'

Here’s the did file I am using: ic/ledger.did at master · dfinity/ic · GitHub

I am using the Wasm file from curl -o ledger.wasm.gz “https://download.dfinity.systems/ic/d6d395a480cd6986b4788f4aafffc5c03a07e46e/canisters/ic-icrc1-ledger.wasm.gz

I am getting this error:

Deploying: ckbtc
All canisters have already been created.
Building canisters...
Installing canisters...
Installing code for canister ckbtc, with canister ID be2us-64aaa-aaaaa-qaabq-cai
Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to deploy canisters.
  Failed while trying to install all canisters.
    Failed to install wasm module to canister 'ckbtc'.
      Failed during wasm installation call: The Replica returned an error: code 5, message: "Canister be2us-64aaa-aaaaa-qaabq-cai trapped explicitly: Panicked at 'Deserialization Failed: "Fail to decode argument 0 from table0 to record {\n  send_whitelist : vec principal;\n  token_symbol : opt text;\n  transfer_fee : opt record { e8s : nat64 };\n  minting_account : text;\n  transaction_window : opt record { secs : nat64; nanos : nat32 };\n  max_message_size_bytes : opt nat64;\n  icrc1_minting_account : opt record {\n    owner : principal;\n    subaccount : opt vec nat8;\n  };\n  archive_options : opt record {\n    num_blocks_to_archive : nat64;\n    max_transactions_per_response : opt nat64;\n    trigger_threshold : nat64;\n    max_message_size_bytes : opt nat64;\n    cycles_for_archive_creation : opt nat64;\n    node_max_memory_size_bytes : opt nat64;\n    controller_id : principal;\n  };\n  initial_values : vec record { text; record { e8s : nat64 } };\n  token_name : opt text;\n}"', rs/rust_canisters/dfn_core/src/endpoint.rs:49:41"

The Candid file and the arguments in the command seem to match up fine, because when I leave something out I get an error about that. So there seems to be something wrong inside of the canister. Have I downloaded the incorrect Wasm somehow? Which is the correct Wasm and did file for the ckBTC canister?

3 Likes

I have pinged the people that developed ckBTC for help. Otherwise I don’t really know how to get it running at the moment. dfx still includes the old BTC integration architecture, so even if you get the canisters installed I’m not sure if everything will work. We’re close to having dfx ready to go with the new BTC canister

1 Like

We’re planning on adding ICRC-2 to the ICP ledger as well.

1 Like

I am pretty sure that the did you are using is the right one but you are not using the icrc1 ledger here. The error you get is because you are trying to install the ICP ledger using ICRC1 installation args. Note that the link you provided seems to be the right one so you may need to check the wasm you are trying to install or the dfx config.

2 Likes

That’s right, I will try to see if I can fix that.

1 Like

Apparently this works

https://download.dfinity.systems/ic/$IC_VERSION/canisters/$CANISTER_NAME_IN_THE_LIST

So for example
https://download.dfinity.systems/ic/b3b00ba59c366384e3e0cd53a69457e9053ec987/canisters/ic-ckbtc-minter

3 Likes

Thanks! I redownloaded the Wasm binary and I suppose it was just wrong. I got it all working! When I mine BTC to an address and call the appropriate methods on the minter the balance reflects in the ckBTC canister, and the KYT is turned off locally (even though I have to provide an empty API string). Thanks everyone!

It’s quite complicated to set this up though, as I’m sure everyone already knows.

5 Likes

I’ll share the result of my multi-day adventure getting ckBTC setup locally here, hopefully it’s helpful.

You can see more in the ckBTC example directory in Azle.

Installation

bitcoind

mkdir .bitcoin
mkdir .bitcoin/data

curl https://bitcoincore.org/bin/bitcoin-core-23.0/bitcoin-23.0-x86_64-linux-gnu.tar.gz -o bitcoin.tar.gz

tar xzf bitcoin.tar.gz --overwrite --strip-components=1 --directory=.bitcoin/ bitcoin-23.0/bin/

rm -rf bitcoin.tar.gz

ckbtc ledger canister

# did file found here: https://github.com/dfinity/ic/blob/master/rs/rosetta-api/icrc1/ledger/ledger.did
cd ckbtc
curl -o ledger.wasm.gz "https://download.dfinity.systems/ic/d6d395a480cd6986b4788f4aafffc5c03a07e46e/canisters/ic-icrc1-ledger.wasm.gz"

internet identity canister

# did file found here: https://github.com/dfinity/internet-identity/blob/main/src/internet_identity/internet_identity.did
cd internet_identity
# Manually download this file from the browser
# https://github.com/dfinity/internet-identity/releases/download/release-2023-05-15/internet_identity_test.wasm.gz

ckbtc kyt canister

# did file found here: https://github.com/dfinity/ic/blob/master/rs/bitcoin/ckbtc/kyt/kyt.did
cd kyt
curl -o kyt.wasm.gz "https://download.dfinity.systems/ic/d6d395a480cd6986b4788f4aafffc5c03a07e46e/canisters/ic-ckbtc-kyt.wasm.gz"

ckbtc minter canister

# did file found here: https://github.com/dfinity/ic/blob/master/rs/bitcoin/ckbtc/minter/ckbtc_minter.did
cd minter
curl -o minter.wasm.gz "https://download.dfinity.systems/ic/d6d395a480cd6986b4788f4aafffc5c03a07e46e/canisters/ic-ckbtc-minter.wasm.gz"

Deployment

bitcoind

# Do this in its own terminal
.bitcoin/bin/bitcoind -conf=$(pwd)/.bitcoin.conf -datadir=$(pwd)/.bitcoin/data --port=18444

dfx

# Do this in its own terminal
dfx start --clean --host 127.0.0.1:8000 --enable-bitcoin

ckbtc ledger canister

dfx deploy ckbtc --specified-id=be2us-64aaa-aaaaa-qaabq-cai --argument='(variant { Init = record { minting_account = record { owner = principal "bd3sg-teaaa-aaaaa-qaaba-cai" }; transfer_fee = 0 : nat64; token_symbol = "ckBTC"; token_name = "ckBTC"; metadata = vec {}; initial_balances = vec {}; archive_options = record { num_blocks_to_archive = 0 : nat64; trigger_threshold = 0 : nat64; controller_id = principal "aaaaa-aa" } } })'

internet identity canister

dfx deploy internet_identity --specified-id 4duc2-jqaaa-aaaaa-aabiq-cai --argument '(null)'

ckbtc kyt canister

dfx deploy kyt --specified-id bkyz2-fmaaa-aaaaa-qaaaq-cai --argument "(variant { InitArg = record { minter_id = principal \"bd3sg-teaaa-aaaaa-qaaba-cai\"; maintainers = vec { principal \"$(dfx identity get-principal)\" }; mode = variant { AcceptAll } } })"

dfx canister call kyt set_api_key '(record { api_key = "" })'

ckbtc minter canister

dfx deploy minter --specified-id bd3sg-teaaa-aaaaa-qaaba-cai --argument '(variant { Init = record {btc_network = variant { Regtest }; min_confirmations=opt 1; ledger_id = principal "be2us-64aaa-aaaaa-qaabq-cai"; kyt_principal = opt principal "bkyz2-fmaaa-aaaaa-qaaaq-cai"; ecdsa_key_name = "dfx_test_key";retrieve_btc_min_amount = 5_000; max_time_in_queue_nanos = 420_000_000_000; mode = variant {GeneralAvailability}} })'

Usage

# Mine some BTC to that address
.bitcoin/bin/bitcoin-cli -conf=$(pwd)/.bitcoin.conf generatetoaddress 1 <your-canister-btc-address>
12 Likes

@Manu thank you for sharing.