UNPKG

@wuwei-labs/srsly

Version:

[![npm version](https://img.shields.io/npm/v/ts-sdk-example.svg)](https://www.npmjs.com/package/ts-sdk-example)

45 lines 1.67 kB
import { getCreateContractInstructionAsync, SRSLY_PROGRAM_ADDRESS, } from '../codama'; import { DEFAULT_GAME_ID, } from '../utils'; /** * Asynchronously creates an instruction to create a rental contract with minimal required parameters. * Derives ownerTokenAccount, contract, and rentalAuthority automatically if not provided. * * @example * ```typescript * // Create the instruction with minimal parameters * const ix = await createContract({ * owner: wallet, * fleet: fleetAddress, * ownerProfile: profileAddress, * rate: 100, // 100 ATLAS per second * durationMin: 3600, // 1 hour in seconds * durationMax: 604800, // 1 week in seconds * paymentsFreq: "daily" * }); * * // Add to transaction and sign * const tx = new Transaction().add(ix); * await sendAndConfirmTransaction(connection, tx, [wallet]); * ``` * * @param params The simplified parameters for creating a rental contract * @returns A promise that resolves to the instruction to create a contract */ export async function createContract(params) { const { owner, fleet, ownerProfile, rate, durationMin, durationMax, paymentsFreq, ownerKeyIndex = 0, gameId = DEFAULT_GAME_ID, } = params; // Let codama derive the rest (contract, rentalAuthority, ownerTokenAccount, etc.) const input = { owner, fleet, ownerProfile, gameId, rate, durationMin, durationMax, paymentsFeq: paymentsFreq, ownerKeyIndex, }; return getCreateContractInstructionAsync(input, { programAddress: SRSLY_PROGRAM_ADDRESS }); } export { getCreateContractInstructionAsync }; //# sourceMappingURL=create.js.map