Mint a Rental NFT
Prerequisites
Before getting started, make sure you have the following ready:
Create a Ternoa account with Alphanet CAPS
Install and set up your editor of choice (we will use Visual Studio Code [VSC] in this tutorial)
Install NodeJS v.14+ & NPM
How to create a rental NFT on-chain?
This function creates a rental NFT on the Ternoa chain. It returns an object promise containing the ContractCreatedEvent provided by the Ternoa blockchain.
:::info Use your own account by updating the //TernoaTestAccount with your account seed when retrieving the keyring from the example below. Replace the variables according to your needs. :::
import {
createContract,
initializeApi,
getKeyringFromSeed,
WaitUntil,
} from "ternoa-js";
//First import the helpers for every parameter you need. Helpers expect the values (strings, number, boolean (..)) and return the corresponding expected object.
import {
formatAcceptanceType,
formatCancellationFee,
formatDuration,
formatRentFee,
} from "ternoa-js/rent/utils";
const createContract = async () => {
try {
await initializeApi();
const keyring = await getKeyringFromSeed("//TernoaTestAccount");
// Here you create some constants with each helper and value you want. We use some random values:
const duration = formatDuration("subscription", 30, 100, true);
const acceptanceType = formatAcceptanceType("manual", null);
const rentFee = formatRentFee("tokens", 1);
const renterCancellationFee = formatCancellationFee("fixed", 1);
const renteeCancellationFee = formatCancellationFee("none");
// Create or retrieve the NFT you want to convert into a rental NFT.
const { nftId } = await createNft(
"hello world",
0,
undefined,
false,
keyring,
WaitUntil.BlockInclusion
);
// Provide each const one by one as parameters in our function below:
const rentalContractData = await createContract(
nftId,
duration,
acceptanceType,
true,
rentFee,
renterCancellationFee,
renteeCancellationFee,
keyring,
WaitUntil.BlockInclusion
);
console.log(`Contract created for NFT: ${rentalContractData.nftId}`);
} catch (e) {
console.error(e);
}
};The expected params
The expected parameters for creating a contract are objects under a specific format. The best practice and the easiest way to create the parameters is to use the formatters we provide.
Response
The response provided from the blockchain event includes all the information below according to the parameters provided when creating a rental NFT.
Support
If you face any trouble, feel free to reach out to our community engineers in our Discord.
Last updated