How to detect deposit BTC on motoko

How to detect user send BTC to my address on motoko? I know that we can “get_utxos” with my address but we don’t know time transaction or anything.
Thanks, you.
This is result of “get_utxos”.

Your application has to keep track of UTXOs iself.
If there is a single user that sends some funds to your canister, you can check if there are UTXOs that the canister has not seen yet. If there are such UTXOs, you can then check if the correct amount was received.

Obviously, this approach doesn’t work well if there are multiple users. In this case, using a derived Bitcoin address for each user is a common solution.

I hope this helps. Let me know if you have any follow-up questions!

How to know “there are UTXOS that the canister has not seen yet”?
If we use “heartbeat” to canister seen UTXOs of each user, it would not good when we have a large number of users.

You are right, if you have many users, calling get_utxos for each user on every heartbeat would be both wasteful and prohibitively expensive.

Unfortunately, there is no easy solution. I would recommend checking out the way the ckBTC minter addresses this problem (you can check out an overview of the architecture as well as the source code).
In short, the idea is that the canister must be informed explicitly about a deposit before it requests the UTXOs.

1 Like

Is the ckBTC release yet? I want to use Mainnet

Yes, ckBTC is available on mainnet:

  • ckBTC minter: mqygn-kiaaa-aaaar-qaadq-cai
  • ckBTC ledger: mxzaz-hqaaa-aaaar-qaada-cai

The ckBTC minter exposes a dashboard with information about UTXOs, retrieval requests, and so on.

Note that the BTC-to-ckBTC is currently restricted, so you can only transfer ckBTC and convert ckBTC back to BTC. You can follow the discussion about ckBTC here.

1 Like