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

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>
13 Likes

@Manu thank you for sharing.

Dear ICP network,

I hope this message finds you well. I am reaching out with a concern regarding the recent minting of ckBTC and the associated BTC transfer. I would greatly appreciate your assistance in clarifying the situation.

Recently, I made the decision to mint some ckBTC, and as instructed by the nns app, I sent a certain amount of BTC to the provided address for receiving ckBTC via the BTC network. However, I now have concerns about the status of my BTC.

Could you kindly confirm whether my BTC is at risk or if there are any potential issues that I should be aware of? I would greatly appreciate any information or guidance you can provide to help me understand the current situation.

Thank you for your attention to this matter. I look forward to your prompt response and resolution.

Could you please share what exactly leads you to believe their may be a problem with the transfer?

12 confirmations are required, once this is complete, the button or link “Refresh balance” can be clicked. This will finalize the conversion from BTC to ckBTC. See

Dear @bobekas

Can you please elaborate on your question a bit more?

Your comment was flagged by some folks as being AI-generated because it is not quite clear what the concern is (but it is verbose). I suspect a quicklfollow up from you would clarify for folks to show them it is not AI spam.

Thank you.

Hi there,


Does the picture mean we can directly transfer btc from the native btc network and no fee?

1 Like

Hi, for now, the fee is deducted from the amount that you can see on your screenshot. We are working on improving the info displayed. In the near future, you should be able to the fee paid for converting ckBTC to BTC.

2 Likes

The picture is somewhat misleading; BTC → ckBTC conversions incur two types of fees:

  1. The fee you pay on the Bitcoin network for transferring BTC to the minter address.
  2. The KYT fee minter draws for BTC → ckBTC conversion.

Unfortunately, this information is not available in the Ledger. We’re planning to make the fees a bit more transparent in the future.

4 Likes

We cannot prevent users and canisters from burning ckBTC; that won’t cause any problems in ckBTC.

The ckBTC promise is that ckBTC in circulation is less than or equal to the minter’s BTC balance, ensuring that the ckBTC minter always holds enough BTC to fulfill BTC withdrawals.

Hi everyone, I tried sending BTC to this Binance address 15CWY94BtR7Vj2XiRYV2bSMkG3A6AuJiCD and I got this error:

{
    "Err": {
        "MalformedAddress": "checksum mismatch expected fed2e77f, got 37a55c06"
    }
}

From what I know the address is a P2PKH address and that is supported by the ckBTC minter. What is the cause of this error and can it be resolved? If not is there a way to know beforehand which addresses are not supported so the withdrawal would not be attempted?

1 Like

We’ll take a look! Thanks for reporting

1 Like

Hi EstherOA, I just tested and it seems the address you provided is right. Could you give more detail on where you tried to send BTC, were you using the NNS dapp? Could you try again and make sure that the pasted address is right?