Configure a marketplace
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 set the marketplace configuration on-chain?
This function updates the marketplace configuration on the Ternoa chain. It returns an object promise containing the MarketplaceConfigSetEvent provided by the Ternoa blockchain.
To avoid any error, we strongly recommend you construct your params using the helpers we provide:
formatMarketplaceFee() for both commission and listing fee.
formatMarketplaceAccountList() for the account list.
formatMarketplaceOffchainData() for the off-chain data.
formatMarketplaceCollectionList() for the collection list.
import {
setMarketplaceConfiguration,
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 {
formatMarketplaceFee,
formatMarketplaceAccountList,
formatMarketplaceOffchainData,
formatMarketplaceCollectionList,
} from "ternoa-js/marketplace/utils";
const createContract = async () => {
try {
await initializeApi();
const keyring = await getKeyringFromSeed("//TernoaTestAccount");
const marketplaceId = //to be updated
const offchainDataHash = //to be updated
const collectionId = //to be updated
const address = //to be updated
// Here you create some constants with each helper and value you want. We use some random values:
const formattedCommissionFee = formatMarketplaceFee(
"set",
"percentage",
10
);
const formattedListingFee = formatMarketplaceFee("set", "flat", 100);
const formattedAccountList = formatMarketplaceAccountList("set", [
address,
]);
const formattedOffchainData = formatMarketplaceOffchainData(
"set",
offchainDataHash
);
const formattedCollectionList = formatMarketplaceCollectionList(
"set",
[collectionId]
);
// Provide each const one by one as parameters in our function below:
const mpEvent = await setMarketplaceConfiguration(
marketplaceId,
formattedCommissionFee,
formattedListingFee,
formattedAccountList,
formattedOffchainData,
formattedCollectionList,
keyring,
WaitUntil.BlockInclusion
);
console.log(`Marketplace: ${mpEvent.nftId} correctly updated`);
} catch (e) {
console.error(e);
}
};The expected params
The expected parameters for updating a marketplace 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 updating the marketplace.
Support
If you face any trouble, feel free to reach out to our community engineers in our Discord.
Last updated