Creating new NFT series

Creating new NFT series

Creating a new NFT series requires function call to the paras token contract. The media and reference must be an IPFS hash OR an absolute URL.

type TokenMetadata = {
  title: string|null, // ex. "Arch Nemesis: Mail Carrier" or "Parcel #5055"
  description: string|null, // free-form description
  media: string|null, // URL to associated media, preferably to decentralized, content-addressed storage
  media_hash: string|null, // Base64-encoded sha256 hash of content referenced by the `media` field. Required if `media` is included.
  copies: number|null, // number of copies of this set of metadata in existence when token was minted.
  issued_at: number|null, // When token was issued or minted, Unix epoch in milliseconds
  expires_at: number|null, // When token expires, Unix epoch in milliseconds
  starts_at: number|null, // When token starts being valid, Unix epoch in milliseconds
  updated_at: number|null, // When token was last updated, Unix epoch in milliseconds
  extra: string|null, // anything extra the NFT wants to store on-chain. Can be stringified JSON.
  reference: string|null, // URL to an off-chain JSON file with more info.
  reference_hash: string|null // Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
}

// Create new series
// Arguments
// * `token_metadata`: approved account to transfer
// * `price`: initial price, null for "not for sale"
// * `royalty`: map of accountId with royalty percentage
function nft_create_series(
   token_metadata: TokenMetadata,
   price: string|null,
   royalty: HashMap<AccountId, U128>,
): TokenSeriesJson

Important metadata

Royalty

Royalty will be divided by 10000, so for 10% royalty, you have to write 1000.

(1000 / 10000 = 0.1)

Using near-cli

near call --accountId projectp.testnet paras-token-v1.testnet nft_create_series '{"creator_id":"projectp.testnet","token_metadata":{"title":"Dark","media":"bafybeifdbvb6yzajogbe4dbn3bgxoli3sp7ol7upfmu2givpvbwufydthu","reference":"bafybeifvzitvju4ftwnkf7w7yakz7i5colcey223uk2ui4t5z3ss7l2od4","copies":100},"price":"1000000000000000000000000","royalty":{"projectp.testnet":100}}' --depositYocto 8540000000000000000000

Using javascript

const nearAPI = require('near-api-js')

const main = async () => {
	const config = {
		networkId: 'testnet',
		nodeUrl: 'https://rpc.testnet.near.org',
		walletUrl: 'https://wallet.testnet.near.org',
		appName: 'Paras Testnet',
		contractName: `paras-token-v2.testnet`
	}

	try {
		// Initializing nearAPI
		// Login and init contract
		const keyStore = new nearAPI.keyStores.UnencryptedFileSystemKeyStore(
			`${process.env.HOME}/.near-credentials/`
		)

		const connection = await nearAPI.connect({
			deps: {
				keyStore: keyStore,
			},
			...config,
		})

		const account_id = 'orang.testnet'
		const account = await connection.account(account_id)

		const contract = await new nearAPI.Contract(
			account,
			config.contractName,
			{
				changeMethods: [
					'nft_create_series'
				],
			}
		)

		const formattedParams = {
				token_metadata: {
					title: 'Dark',
					media: 'bafybeifdbvb6yzajogbe4dbn3bgxoli3sp7ol7upfmu2givpvbwufydthu',
					reference: 'bafybeifvzitvju4ftwnkf7w7yakz7i5colcey223uk2ui4t5z3ss7l2od4',
					copies: 100 
				},
				price: null,
				royalty: {
					[account_id]: 1000
				}
		}

		const ret = await contract.nft_create_series(
			formattedParams,
			300000000000000, //	attached GAS
			"8540000000000000000000"
		)

		console.log(ret)
	} catch (err) {
		throw err
	}
}

main()

Last updated