@mysten/sui v2.0 and a new dApp Kit are here! Check out the migration guide
Mysten Labs SDKs

Advanced Examples

Advanced Kiosk SDK usage patterns and examples

Some extended examples

For these examples, assume you have the following data and functions available:

import { kiosk, KioskTransaction } from '@mysten/kiosk';
import { SuiJsonRpcClient, getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc';

// a constant for bullshark's type.
const bullsharkType = `${packageId}::suifrens::SuiFren<${packageId}::bullshark::Bullshark>`;
// a constant for capy's type.
const capyType = `${packageId}::suifrens::SuiFren<${packageId}::capy::Capy>`;

// initialize the client with the kiosk extension.
const client = new SuiJsonRpcClient({
	url: getJsonRpcFullnodeUrl('mainnet'),
	network: 'mainnet',
}).$extend(kiosk());

Minting a SuiFren

This example demonstrates how to mint a SuiFren.

async function mintFren(address: string) {
	const { kioskOwnerCaps } = await client.kiosk.getOwnedKiosks({ address });

	// Choose the first kiosk for simplicity. We could have extra logic here (e.g. let the user choose, pick a personal one, etc).
	const cap = kioskOwnerCaps[0];

	const tx = new Transaction();
	const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });

	// We're mixing the logic here. If the cap is undefined, we create a new kiosk.
	if (!cap) kioskTx.create();

	// Let's mint a capy here into the kiosk (either a new or an existing one).
	tx.moveCall({
		target: `${packageId}::suifrens::mint_app::mint`,
		arguments: [kioskTx.getKiosk(), kioskTx.getKioskCap()],
		typeArguments: [capyType],
	});

	// If we don't have a cap, that means we create a new kiosk for the user in this flow.
	if (!cap) kioskTx.shareAndTransferCap(address);

	kioskTx.finalize();

	// sign and execute transaction.
	await signAndExecuteTransaction({ tx: tx });
}

Mixing two Suifrens

This example demonstrates how to use the Kiosk SDK to mix two bullsharks.

// We're mixing two frens.
async function mixFrens(firstFrenObjectId: string, secondFrenObjectId: string, cap: KioskOwnerCap) {
	const tx = new Transaction();
	const kioskTx = new KioskTransaction({ transaction: tx, kioskClient: client.kiosk, cap });

	// borrow both frens.
	const [fren1, promise1] = kioskTx.borrow({
		itemType: bullsharkType,
		itemId: firstFrenObjectId,
	});

	const [fren2, promise2] = kioskTx.borrow({
		itemType: bullsharkType,
		itemId: secondFrenObjectId,
	});

	// Let's call the mix function. We skip any payment related stuff here.
	tx.moveCall({
		target: `${packageId}::mix_app::mix`,
		arguments: [fren1, fren2, kioskTx.getKiosk(), kioskTx.getKioskCap()],
		typeArguments: [bullsharkType],
	});

	kioskTx
		.return({
			itemType: bullsharkType,
			item: fren1,
			promise: promise1,
		})
		.return({
			itemType: bullsharkType,
			item: fren2,
			promise: promise2,
		})
		.finalize();

	// sign and execute transaction.
	await signAndExecuteTransaction({ tx: tx });
}

On this page