Post
Share your knowledge.
How to use to query kiosks?
Anyone know what I can use to query kiosks in wallet and their objects within it? Im having trouble with finding an example online or on Sui's documentation. so far, im able to pull domains and some NFT's, but kiosks and NFTs within them im not to certain.
- Sui
Answers
12Sui does not use passphrases; accounts are created from cryptographic key pairs. In a React app, use the Sui TypeScript SDK to generate a new key pair and derive the Sui address. For reference, see the official Sui SDK and wallet repositories on GitHub, which provide examples of secure account generation and management.
Sui does not use passphrases; accounts are created from cryptographic key pairs. In a React app, use the Sui TypeScript SDK to generate a new key pair and derive the Sui address. For reference, see the official Sui SDK and wallet repositories on GitHub, which provide examples of secure account generation and management.
To query kiosks and their objects in Sui, you can use the Sui Client SDK or direct GraphQL queries to the Sui RPC endpoint. Start by fetching kiosk owner data with getOwnedObjects, filtering for the kiosk::Kiosk type. Once you have the kiosk IDs, use getDynamicFields to retrieve the objects stored within each kiosk. For NFTs inside kiosks, check the kiosk::Item type and decode the object data.
To query kiosks and their associated NFTs in a Sui wallet, the process typically involves interacting with objects (e.g., NFT collections) stored in kiosks, which are essentially on-chain smart contract containers or containers of objects.
While the Sui documentation provides some information about querying objects, querying kiosks specifically and their contents (NFTs) is a slightly different case. Kiosks may be implemented as custom objects or smart contracts that contain and manage collections of NFTs or other objects.
Here’s a step-by-step guide to help you query kiosks and NFTs within them on Sui.
1. Identify Kiosk Objects
A kiosk is likely represented by a specific object type in Sui. It could be a custom Move module that defines a structure holding NFTs or other assets. To query kiosks, you first need to understand the object structure in the Sui network.
- Kiosks: In many cases, kiosks are implemented as Move smart contracts or containers that hold specific types of objects (like NFTs). To access these, you need to know the object ID and structure.
2. Querying Objects in Sui
To interact with kiosks and NFTs, you'll need to use the Sui RPC API or Sui Client SDK to fetch objects by their object IDs.
Using the Sui CLI to Query Objects
You can start by querying the object IDs associated with a particular kiosk or collection. If you know the address or ID of a kiosk, you can query its objects as follows:
sui client query --object <object_id>
This command will retrieve details about an object, including the contents and state.
Example:
If you know the object ID of a kiosk (e.g., a container of NFTs), you can use the following:
sui client query --object 0x1234567890abcdef1234567890abcdef12345678
This will return data about the object, including any NFTs or tokens within the kiosk.
3. Query NFTs within Kiosks
To query NFTs within a specific kiosk, you will need to:
- Know the Move module used to define NFTs in that kiosk (for example, a module like
0x2::nft). - Query the objects stored in the kiosk, filtering for NFTs based on their types or the specific Move module that governs them.
You would likely need to filter objects by their types or module. You can do this by using sui client to interact with these objects, providing the object type to narrow the search.
sui client query --object-type 0x2::nft::NFT
This command queries the NFTs stored in objects that use the 0x2::nft Move module.
4. Using the Sui SDK to Query Kiosks
If you're using TypeScript or JavaScript to interact with the Sui Client SDK, you can fetch objects associated with kiosks or NFTs using the SDK methods.
Example Code:
Here’s how you might use the Sui SDK in JavaScript or TypeScript to query kiosks and their NFTs:
import { SuiClient, ObjectId } from '@mysten/sui.js';
const client = new SuiClient({ rpcUrl: 'https://testnet.sui.io/rpc' });
async function queryKiosk(kioskId: string) {
try {
// Query the object representing the kiosk by its ID
const kioskObject = await client.queryObject(kioskId);
// Assuming the kiosk contains NFTs, you can check for NFT type in the object
const nftObjects = kioskObject?.data?.filter((obj: any) => obj.type === '0x2::nft::NFT');
console.log('NFTs within the Kiosk:', nftObjects);
return nftObjects;
} catch (error) {
console.error('Error querying kiosk:', error);
}
}
queryKiosk('0x1234567890abcdef1234567890abcdef12345678');
5. Filtering NFTs in Kiosks
To filter NFTs specifically, look at the object type in the kiosk. You can filter by object type using the object query parameters, specifying the Move module (e.g., 0x2::nft::NFT) to identify NFTs stored within the kiosk.
Example Filtering Code:
async function fetchNFTsInKiosk(kioskId: string) {
const kioskData = await client.queryObject(kioskId);
// Filter NFTs in the kiosk based on type
const nftObjects = kioskData.data.filter((obj: any) => obj.type === '0x2::nft::NFT');
return nftObjects;
}
This ensures you're specifically looking for NFTs and can act upon them.
6. Transaction Flow and Metadata
If you want to interact with NFTs in kiosks (e.g., transfer NFTs, query their metadata, etc.), you'll use Move calls from the Sui SDK. Each NFT may have its own metadata stored within it, and you can retrieve this metadata using the object ID or by using Move functions that expose the metadata of NFTs.
const nftMetadata = await client.queryObject(nftObjectId);
console.log('NFT Metadata:', nftMetadata);
7. Using Sui Explorer
You can also use Sui Explorer or Suivision to manually look up kiosks and their contents. While this is not programmatic, it's useful for inspecting data visually if you're debugging or verifying what objects are stored in the kiosk.
8. Common Issues
- Object Types: If kiosks or NFTs are implemented using custom Move modules, you must know the specific module and type used. Check the SDK documentation or Move source code to understand the object types.
- Data Access: Make sure that your kiosk or NFTs are correctly initialized and that you have the appropriate permissions to access them (depending on the context).
9. Further Research
Check Sui's Move code for the kiosk module or NFT module if available. If the module is custom, you might need to adjust your code accordingly.
Conclusion
To query kiosks and their NFTs on Sui:
- Identify the object type used to store kiosks or NFTs (likely a custom Move module).
- Use Sui RPC or SDK to query these objects by ID.
- Filter the objects by their types (e.g.,
0x2::nft::NFT). - Use the
client.queryObject()method or similar functionality in your application to retrieve the NFTs and other objects.
By following these steps, you can successfully query kiosks and NFTs within them on Sui. If you have access to a specific custom module or more documentation, you can fine-tune the queries to suit your needs.
Use getOwnedObjects for KioskOwnerCap and getDynamicFields for kiosk contents:
1. Fetch Kiosks
const kiosks = await client.getOwnedObjects({
owner: '0xYourAddress',
filter: { StructType: '0x2::kiosk::KioskOwnerCap' }
});
2. Fetch Kiosk NFTs
const kioskItems = await client.getDynamicFields({
parentId: kioskId // From KioskOwnerCap
});
Use sui.getOwnedObjects with type: "0x...::kiosk::Kiosk" to find kiosks, then sui.getDynamicFields on the kiosk object to list NFTs inside. Check Kiosk contract types for exact struct names.
1. Query All Kiosks (CLI)
# Get all kiosk objects owned by an address
sui client objects --owner <WALLET_ADDRESS> --filter "StructType=0x2::kiosk::Kiosk"
2. Fetch Kiosk Contents (TypeScript)
import { SuiClient } from '@mysten/sui.js/client';
const client = new SuiClient({ url: 'https://fullnode.mainnet.sui.io' });
async function getKioskContents(kioskId: string) {
// Get dynamic fields (items in kiosk)
const { data } = await client.getDynamicFields({
parentId: kioskId,
});
// Fetch each object
const objects = await client.multiGetObjects({
ids: data.map(field => field.objectId),
options: { showContent: true }
});
return objects;
}
3. Find Kiosks by Owner
const kiosks = await client.getOwnedObjects({
owner: '0xYOUR_WALLET',
filter: { StructType: '0x2::kiosk::Kiosk' },
options: { showContent: true }
});
Key Points
- Kiosks use dynamic fields to store objects
- Each item is a
KioskItemwith:objectId: The stored NFT/objectpolicy: Access control rules
To query kiosks and their contents on Sui, you’ll need to interact with the Kiosk smart contract objects, which are structured a bit differently from standard NFTs held in an account. Here's how you can do it:
-
Query Owned Objects for Kiosks: Use the sui_getOwnedObjects RPC method to list all objects owned by an address, and filter by type to find 0x2::kiosk::Kiosk or 0x2::kiosk::OwnerCap.
-
Fetch Kiosk Details: Once you have the Kiosk object ID, use sui_getObject or sui_tryGetPastObject to fetch its data. You’ll typically find a vector of items or links to listed items within its fields.
3.* Use the TypeScript SDK: The Sui TypeScript SDK includes helpers like getOwnedKiosks(address) in experimental modules. This returns kiosk IDs and linked NFTs.*
- CLI Example:
sui client objects --owner
--filter StructType=0x2::kiosk::Kiosk- Reading Kiosk Contents: After fetching the kiosk object, look into its items field (usually a Table or vector). You’ll then need to recursively query the object IDs found there to get full metadata.
You won’t find full kiosk contents just by scanning wallet NFTs because items inside kiosks aren’t technically “owned” by the wallet in a direct way. They're owned by the kiosk contract. That's why fetching from kiosk state is necessary.
Querying kiosks and their contents in Sui requires a slightly deeper understanding of how objects are stored and structured. Kiosks are not simple owned objects like NFTs in a wallet but smart contract-managed containers. To start, you can use the sui_getOwnedObjects RPC call to fetch objects owned by a user. You'll need to filter the result for types like 0x2::kiosk::Kiosk and 0x2::kiosk::OwnerCap. The OwnerCap is the object that gives a wallet permission to manage a kiosk. Once you identify a kiosk, use sui_getObject or sui_tryGetPastObject to fetch its on-chain data.
Kiosks typically store references to their items using fields like items, which might be a Table or vector. To access the actual NFTs stored in the kiosk, you'll need to query those linked object IDs. This is different from querying wallet-owned NFTs because those are directly in the wallet’s possession. Kiosk items, on the other hand, are owned by the kiosk contract. This ownership model allows for listing, transferring, or renting NFTs while keeping them under programmatic control.
In the Sui TypeScript SDK, experimental APIs support kiosk queries. You can use functions like getOwnedKiosks(address) or getKioskContents(kioskId) to simplify access. These helpers abstract away the need to manually traverse fields and decode tables. For advanced developers, writing a custom Move module that interacts with 0x2::kiosk could be an option. You’d need to read the Kiosk standard in the Sui framework to fully parse its storage structure.
On the CLI side, use sui client objects --owner
to list objects, then filter for kiosk types. After identifying the kiosk object, use sui client objectDo 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.
- How to Maximize Profit Holding SUI: Sui Staking vs Liquid Staking616
- Why does BCS require exact field order for deserialization when Move structs have named fields?65
- Multiple Source Verification Errors" in Sui Move Module Publications - Automated Error Resolution55
- Sui Move Error - Unable to process transaction No valid gas coins found for the transaction419
- Sui Transaction Failing: Objects Reserved for Another Transaction410