Managing Owned Kiosk
KioskClient
helps in managing a kiosk.
You need to follow the steps explained in the Kiosk Transaction section to
create a KioskTransaction
.
Available functions
take
Removes an item from the Kiosk and returns a TransactionArgument
to use it in a different
Programmable Transaction Block (PTB) call.
const item = '0xHeroAddress';
const itemType = '0x..::hero::Hero';
/// Assume `kioskClient` and `cap` are supplied to the function as explained in the previous section.
const tx = new Transaction();
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient, cap });
// Take item from kiosk.
const item = kioskTx.take({
itemId: item,
itemType,
});
// Do something with `item`, like transfer it to someone else.
tx.transferObjects([item], 'address_to_transfer_the_object');
// Finalize the kiosk Tx.
kioskTx.finalize();
// Sign and execute transaction.
await signAndExecuteTransaction({ tx });
transfer
Similar to take
, but transfers the item to an address internally.
const item = '0xHeroAddress';
const itemType = '0x..::hero::Hero';
/// Assume `kioskClient` and `cap` are supplied to the function as explained in the previous section.
const tx = new Transaction();
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient, cap });
// Take item from kiosk.
kioskTx
.transfer({
itemId: item,
itemType,
address: 'address_to_transfer_the_object',
})
.finalize();
// Sign and execute transaction.
await signAndExecuteTransaction({ tx });
place
Places an item in the kiosk.
const item = '0xHeroAddress';
const itemType = '0x..::hero::Hero';
/// Assume `kioskClient` and `cap` are supplied to the function as explained in the previous section.
const tx = new Transaction();
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient, cap });
kioskTx
.place({
item,
itemType,
})
.finalize();
// Sign and execute transaction.
await signAndExecuteTransaction({ tx });
list
Lists an item for sale (the item must be in the kiosk).
const itemId = '0xHeroAddress';
const itemType = '0x..::hero::Hero';
// Assume `kioskClient` and `cap` are supplied to the function as explained in the previous section.
const tx = new Transaction();
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient, cap });
kioskTx
.list({
itemId,
itemType,
price: 100000n,
})
.finalize();
// Sign and execute transaction.
await signAndExecuteTransaction({ tx });
placeAndList
List an item for sale by first placing it in the kiosk (places the item and lists it for sale). It's
a short hand for place()
and list()
.
const item = '0xHeroAddress';
const itemType = '0x..::hero::Hero';
// Assume `kioskClient` and `cap` are supplied to the function as explained in the previous section.
const tx = new Transaction();
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient, cap });
kioskTx
.placeAndList({
itemId,
itemType,
price: 100000n,
})
.finalize();
// Sign and execute transaction.
await signAndExecuteTransaction({ tx });
delist
Removes the listing, keeping the item placed in the kiosk.
const itemId = '0xHeroAddress';
const itemType = '0x..::hero::Hero';
/// assume `kioskClient` and `cap` are supplied to the function as explained in the previous section.
const tx = new Transaction();
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient, cap });
kioskTx
.delist({
itemId,
itemType,
})
.finalize();
// sign and execute transaction.
await signAndExecuteTransaction({ tx });
withdraw
Withdraw (all or specific amount) from a kiosk.
amount
: Can be empty, which will withdraw all the funds.
// Assume `kioskClient` and `cap` are supplied to the function as explained in the previous section.
const tx = new Transaction();
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient, cap });
kioskTx
.withdraw({
address: 'address_to_transfer_funds',
amount: 100000n,
})
.finalize();
// Sign and execute transaction.
await signAndExecuteTransaction({ tx });
borrowTx (callback)
Borrows an item from a kiosk. This function follows the callback
approach, similar to the
ownerCap. The return of the item happens automatically after the execution of the callback.
const itemId = '0xHeroAddress';
const itemType = '0x..::hero::Hero';
/// assume `kioskClient` and `cap` are supplied to the function as explained in the previous section.
const tx = new Transaction();
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient, cap });
kioskTx
.borrowTx(
{
itemId,
itemType,
},
(item) => {
tx.moveCall({
target: '0xMyGame::hero::level_up',
arguments: [item],
});
},
)
.finalize();
// Sign and execute transaction.
await signAndExecuteTransaction({ tx });
borrow / return
Similar to borrowTx
, borrows an item from the kiosk, but returns two transaction arguments: item
& promise
. You can use the item
in your PTBs, but you must always call the return()
function
with the item
and the Promise
.
const itemId = '0xHeroAddress';
const itemType = '0x..::hero::Hero';
// Assume `kioskClient` and `cap` are supplied to the function as explained in the previous section.
const tx = new Transaction();
const kioskTx = new KioskTransaction({ transaction: tx, kioskClient, cap });
const [item, promise] = kioskTx.borrow({
itemId,
itemType,
});
tx.moveCall({
target: '0xMyGame::hero::level_up',
arguments: [item],
});
kioskClient
.return({
itemType,
item,
promise,
})
.finalize();
// Sign and execute transaction.
await signAndExecuteTransaction({ tx });