Post
Share your knowledge.
How to find the treasury cap object ID for a coin type?
I want to know how can I get the object ID of a treasury cap for a coin, given only the coin type name. Currently, I'm fetching the metadata object and checking its previous transactions to find the treasury cap object, but this method seems inefficient. I'm looking for an easier and more efficient way to determine if a coin mint is frozen by using the coin type name. Any suggestions?
- Sui
Answers
4If the treasury cap has been transferred to another address, you can configure your query to include owner information. Use the following configuration in your query: QUERY_OPTIONS
and QUERY_FILTER
, and specify the expected owner or filter for the TreasuryCap
struct type.
It's critical to ensure you transfer the coin object correctly during initialization. Confirm that when using transfer::public_transfer(treasury, tx_context::sender(ctx))
, the correct address is chosen for the transfer.
Remember, if you're just fetching this info for random coins and only have the coin type name, you'll need to adapt your approach, as coin creation details might be unknown.
When you mint a Coin, you can use let (treasury, metadata) = coin::create_currency
, where the ctx.sender()
receives the Coin Treasury object. To locate this object, use getOwnedObjects
from the React SDK and filter by the Treasury
object type.
Do you know the answer?
Please log in and share it.
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.