Unique Network is a scalable blockchain for composable NFTs with advanced economies — The NFT chain built for Polkadot and Kusama. This is an SDK for working with Unique Network.
You need to do the installation of npm packages for the next build of the project.
yarn install
or
npm install
The project will be compiled from typescript scripts. The compiled files will be stored here /packages/apps/build
yarn run build
The Unique API object is global, and is added to the windows object.
const createApi = async () => {
const uniqueApi = new UniqueAPI({
endPoint: 'wss://testnet2.uniquenetwork.io' //Network address
});
uniqueApi.marketContractAddress = '5GP...'; //The address of the contract, you need if you will buy or sell tokens.
uniqueApi.escrowAddress = '5DA...'; //The escrow address is needed for the purchase and sale of tokens
uniqueApi.signer = '5D4...'; //Your address in polkadot.js
await uniqueApi.connect();
return uniqueApi;
}
const uniqueApi = await createApi();
Buy of a token. To buy a token, calls the method buyOnMarket
uniqueApi.collectionId = 112; // Collection number
await uniqueApi.buyOnMarket(53); // token number
Cancellation token
uniqueApi.collectionId = 112; // Collection number
await uniqueApi.cancelOnMarket(53); // token number
Get information about the token
api.collectionId = 112; // Collection number
let token = await uniqueApi.getNftProperties(25); // token number
Sell a token
uniqueApi.collectionId = 112; // Collection number
await uniqueApi.listOnMarket(53, 2); // token 53, price 2 KSM
Get the token price. The function returns the price in BigNumber
uniqueApi.collectionId = 112; // Collection number
let price = await uniqueApi.getMarketPrice(53); // token number