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 txb = new TransactionBlock();
const kioskTx = new KioskTransaction({ transactionBlock: txb, kioskClient, cap });
// Take item from kiosk.
const item = kioskTx.take({
itemId: item,
itemType,
});
// Do something with `item`, like transfer it to someone else.
txb.transferObjects([item], txb.pure('address_to_transfer_the_object'));
// Finalize the kiosk Tx.
kioskTx.finalize();
// Sign and execute transaction block.
await signAndExecuteTransactionBlock({ tx: txb });
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 txb = new TransactionBlock();
const kioskTx = new KioskTransaction({ transactionBlock: txb, kioskClient, cap });
// Take item from kiosk.
kioskTx
.transfer({
itemId: item,
itemType,
address: 'address_to_transfer_the_object',
})
.finalize();
// Sign and execute transaction block.
await signAndExecuteTransactionBlock({ tx: txb });
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 txb = new TransactionBlock();
const kioskTx = new KioskTransaction({ transactionBlock: txb, kioskClient, cap });
kioskTx
.place({
item,
itemType,
})
.finalize();
// Sign and execute transaction block.
await signAndExecuteTransactionBlock({ tx: txb });
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 txb = new TransactionBlock();
const kioskTx = new KioskTransaction({ transactionBlock: txb, kioskClient, cap });
kioskTx
.list({
itemId,
itemType,
price: 100000n,
})
.finalize();
// Sign and execute transaction block.
await signAndExecuteTransactionBlock({ tx: txb });
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 txb = new TransactionBlock();
const kioskTx = new KioskTransaction({ transactionBlock: txb, kioskClient, cap });
kioskTx
.placeAndList({
itemId,
itemType,
price: 100000n,
})
.finalize();
// Sign and execute transaction block.
await signAndExecuteTransactionBlock({ tx: txb });
delist
Removes the listing, keeping the item placed in the kiosk.
const itemId = '0xHeroAddress';
const itemType = '0x..::hero::Hero';
/// asume `kioskClient` and `cap` are supplied to the function as explained in the previous section.
const txb = new TransactionBlock();
const kioskTx = new KioskTransaction({ transactionBlock: txb, kioskClient, cap });
kioskTx
.delist({
itemId,
itemType,
})
.finalize();
// sign and execute transaction block.
await signAndExecuteTransactionBlock({ tx: txb });
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 txb = new TransactionBlock();
const kioskTx = new KioskTransaction({ transactionBlock: txb, kioskClient, cap });
kioskTx
.withdraw({
address: 'address_to_transfer_funds',
amount: 100000n,
})
.finalize();
// Sign and execute transaction block.
await signAndExecuteTransactionBlock({ tx: txb });
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';
/// asume `kioskClient` and `cap` are supplied to the function as explained in the previous section.
const txb = new TransactionBlock();
const kioskTx = new KioskTransaction({ transactionBlock: txb, kioskClient, cap });
kioskTx
.borrowTx(
{
itemId,
itemType,
},
(item) => {
txb.moveCall({
target: '0xMyGame::hero::level_up',
arguments: [item],
});
},
)
.finalize();
// Sign and execute transaction block.
await signAndExecuteTransactionBlock({ tx: txb });
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 txb = new TransactionBlock();
const kioskTx = new KioskTransaction({ transactionBlock: txb, kioskClient, cap });
const [item, promise] = kioskTx.borrow({
itemId,
itemType,
});
txb.moveCall({
target: '0xMyGame::hero::level_up',
arguments: [item],
});
kioskClient
.return({
itemType,
item,
promise,
})
.finalize();
// Sign and execute transaction block.
await signAndExecuteTransactionBlock({ tx: txb });