Querying
You can use the kioskClient
to query kiosk data. It helps you get owned kiosks for an address, as
well as fetching all the contents of a specified kiosk.
Querying owned kiosks
Querying owned kiosks returns a list of kioskOwnerCaps
, as well as a list of the kioskIds
.
KioskOwnerCap
is important in this case, as it is used for managing an owned kiosk, as well as
purchasing.
const kioskClient = new KioskClient({...});
const address = '0xAddress'
// You can perform actions, like querying the owned kiosks for an address.
const { kioskOwnerCaps, kioskIds } = await kioskClient.getOwnedKiosks({ address });
console.log(kioskOwnerCaps);
/**
* An example response for an address that owns two kiosks (one of which is personal)
[
{
isPersonal: true,
digest: '9mstxLa87E3VEewQ62EEQDKb7ZH2irrEXeMetQjQHzXz',
version: '18',
objectId: '0x5d4df1b8da5e1b6bafbb4b7dc5c73e532324d82c86e331f71bf1ea5dff18dccc',
kioskId: '0x8453fc71611ce8ff73efcca42ed241dcaf7dc65411b56a7be42e6a0bc3d72c13'
},
{
isPersonal: false,
digest: '8fsKgCh5c2ycPKMVUqUz2H6D9WkPjRHmGP454z67afJh',
version: '15',
objectId: '0x84f5a9a1379d73eceae03d0578637936e208daa809e04ec07a8085c798a980fd',
kioskId: '0xf8c826aae52bc576768032ce496b7fc349f9003603ed1541c8033fc5c2dd2d2c'
}
]
*/
Querying kiosk content
You can follow the sample to query a kiosk's contents. We recommend saving the items
structure
(KioskItem
), as it's useful when you're trying to purchase from one.
listing
field only applies on items that are listed for sale.
const kioskClient = new KioskClient({...});
const id = `0xKioskId`;
// You can perform actions, like querying the owned kiosks for an address.
const res = await kioskClient.getKiosk({
id,
options: {
withKioskFields: true, // this flag also returns the `kiosk` object in the response, which includes the base setup
withListingPrices: true, // This flag enables / disables the fetching of the listing prices.
}
});
console.log(res);
/**
* An example response of an existing kiosk
*
{
items: [
{
objectId: '0xf65e88a33466763cabd11b7c2a57938cf4fa707c6cf767cb428894e14caf1537',
type: '0xd12f8e0fdae3f5d88d2fc4af2e869ea503491e2d8da5f3136320b65bdcf70ab3::hero::Hero',
isLocked: false,
kioskId: '0x6d45df1942c11048a9182e3f732262e6e3c95ddd2e5f338c565f531717c2617f',
listing: undefined,
data: {
objectId: '0xf65e88a33466763cabd11b7c2a57938cf4fa707c6cf767cb428894e14caf1537',
version: '18',
digest: 'As9fkLEP4QVChhYuGemB185xyyzWG4hspSa3UZ6TWR8b',
display: { data: null, error: null },
content: {
dataType: 'moveObject',
type: '0xd12f8e0fdae3f5d88d2fc4af2e869ea503491e2d8da5f3136320b65bdcf70ab3::hero::Hero',
hasPublicTransfer: true,
fields: {
id: {
id: '0xf65e88a33466763cabd11b7c2a57938cf4fa707c6cf767cb428894e14caf1537'
},
level: 3
}
}
}
},
{
objectId: '0x34def97cb8c357fcfdf22f72421d4f6f01706662acf7be1afb6e7391d5491372',
type: '0xd12f8e0fdae3f5d88d2fc4af2e869ea503491e2d8da5f3136320b65bdcf70ab3::hero::Hero',
isLocked: true,
kioskId: '0x6d45df1942c11048a9182e3f732262e6e3c95ddd2e5f338c565f531717c2617f',
listing: undefined,
data: {
objectId: '0x34def97cb8c357fcfdf22f72421d4f6f01706662acf7be1afb6e7391d5491372',
version: '15',
digest: 'J1MdmHUCXJEKd86rkmMwWASMV86wGkVS9P6SFPyRaKVV',
display: { data: null, error: null },
content: {
dataType: 'moveObject',
type: '0xd12f8e0fdae3f5d88d2fc4af2e869ea503491e2d8da5f3136320b65bdcf70ab3::hero::Hero',
hasPublicTransfer: true,
fields: {
id: {
id: '0x34def97cb8c357fcfdf22f72421d4f6f01706662acf7be1afb6e7391d5491372'
},
level: 1
}
}
}
}
],
itemIds: [
'0xf65e88a33466763cabd11b7c2a57938cf4fa707c6cf767cb428894e14caf1537',
'0x34def97cb8c357fcfdf22f72421d4f6f01706662acf7be1afb6e7391d5491372'
],
listingIds: [],
extensions: [],
kiosk: {
id: '6d45df1942c11048a9182e3f732262e6e3c95ddd2e5f338c565f531717c2617f',
profits: '100000',
owner: '96300f8d9064f954f99db2d7fbe2ad0c5e4344f0e22392330285d399498cfaf3',
itemCount: 2,
allowExtensions: false
}
}
*/
Querying transfer policy for type
const kioskClient = new KioskClient({...});
const itemType = '0xAddress::hero::Hero';
// You can perform actions, like querying the owned kiosks for an address.
const policies = await kioskClient.getTransferPolicies(itemType)
console.log(policies);
/* An example output of the response
[
{
id: '0x074847055fe4ea9a7f51eeaf095c05875509403059115af121cfea9b8de355de',
type: '0x2::transfer_policy::TransferPolicy<0x85926b03d56e49bedfca558fc6a2540d43bdfb5c218190d63b571f33afe255f8::hero::Hero>',
owner: { Shared: { initial_shared_version: 5 } },
rules: [
'a82212d931d3bc7c3401552d935abced7b7fd41d4f57a99f0f47b9196b2f57f5::kiosk_lock_rule::Rule',
'a82212d931d3bc7c3401552d935abced7b7fd41d4f57a99f0f47b9196b2f57f5::floor_price_rule::Rule',
'a82212d931d3bc7c3401552d935abced7b7fd41d4f57a99f0f47b9196b2f57f5::royalty_rule::Rule',
'a82212d931d3bc7c3401552d935abced7b7fd41d4f57a99f0f47b9196b2f57f5::personal_kiosk_rule::Rule'
],
balance: '20000'
}
]
*/
Get owned transfer policies
Queries to find all the owned transfer policies. Useful to manage transfer policies, and can be
combined with TransferPolicyTransaction
to easily add or remove rules and withdraw profits.
// Assuming we have a kioskClient instance.
const kioskClient = new KioskClient({...});
// The address that owns the transfer policies.
const address = '0xAddress';
// You can perform actions, like querying the owned kiosks for an address.
const policies = await kioskClient.getOwnedTransferPolicies({ address });
console.log(policies);
/**
* An example output of the response
[
{
policyId: '0x6b6eca8df6e70ea6447e639ef26b519039b5e9123642258eea1b3c781e94faca',
policyCapId: '0x34a4794d4ad6578ac345d23ca0f7a4632ca88de297daaf24a1cdbc91e1547be4',
type: '0xbe01d0594bedbce45c0e08c7374b03bf822e9b73cd7d555bf39c39bbf09d23a9::hero::Hero'
},
{
policyId: '0x87ac2dd80011ed2de9c7916a19145ff520959acd3d8c3dbd100aa74b34155a0a',
policyCapId: '0x858edda13c5c9086b2491eafed39e0ea58511268bb90d90464a2d7b5ed3f3880',
type: '0xbe01d0594bedbce45c0e08c7374b03bf822e9b73cd7d555bf39c39bbf09d23a9::hero::Villain'
}
]
*/
Get owned transfer policies by type
Queries to find all the owned transfer policies for a specific type. Useful to manage transfer policies, and can be combined with
// Assuming you have a kioskClient instance.
const kioskClient = new KioskClient({...});
// The address that owns the transfer policies.
const address = '0xAddress';
// The type of the transfer policy.
const type = '0xbe01d0594bedbce45c0e08c7374b03bf822e9b73cd7d555bf39c39bbf09d23a9::hero::Hero';
// We can query by type.
const policies = await kioskClient.getOwnedTransferPoliciesByType({ address, type });
// An example output of the response
// [
// {
// policyId: '0x6b6eca8df6e70ea6447e639ef26b519039b5e9123642258eea1b3c781e94faca',
// policyCapId: '0x34a4794d4ad6578ac345d23ca0f7a4632ca88de297daaf24a1cdbc91e1547be4',
// type: '0xbe01d0594bedbce45c0e08c7374b03bf822e9b73cd7d555bf39c39bbf09d23a9::hero::Hero'
// }
// ]