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.
1
type TokenMetadata = {
2
title: string|null, // ex. "Arch Nemesis: Mail Carrier" or "Parcel #5055"
3
description: string|null, // free-form description
4
media: string|null, // URL to associated media, preferably to decentralized, content-addressed storage
5
media_hash: string|null, // Base64-encoded sha256 hash of content referenced by the `media` field. Required if `media` is included.
6
copies: number|null, // number of copies of this set of metadata in existence when token was minted.
7
issued_at: number|null, // When token was issued or minted, Unix epoch in milliseconds
8
expires_at: number|null, // When token expires, Unix epoch in milliseconds
9
starts_at: number|null, // When token starts being valid, Unix epoch in milliseconds
10
updated_at: number|null, // When token was last updated, Unix epoch in milliseconds
11
extra: string|null, // anything extra the NFT wants to store on-chain. Can be stringified JSON.
12
reference: string|null, // URL to an off-chain JSON file with more info.
13
reference_hash: string|null // Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
14
}
15
16
// Create new series
17
// Arguments
18
// * `token_metadata`: approved account to transfer
19
// * `price`: initial price, null for "not for sale"
20
// * `royalty`: map of accountId with royalty percentage
21
function nft_create_series(
22
token_metadata: TokenMetadata,
23
price: string|null,
24
royalty: HashMap<AccountId, U128>,
25
): TokenSeriesJson
Copied!

Important metadata

Metadata
Explanation
title
Example: "Key to Paras", the first minted NFT will have "Key to Paras #1" as the title
media
IPFS hash of an image or GIF
reference
IPFS hash of JSON document
copies
This will determined how many NFTs can be minted

Royalty

Royalty will be divided by 10000, so for 10% royalty, you have to write 1000.
(1000 / 10000 = 0.1)

Using near-cli

1
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
Copied!

Using javascript

1
const nearAPI = require('near-api-js')
2
3
const main = async () => {
4
const config = {
5
networkId: 'testnet',
6
nodeUrl: 'https://rpc.testnet.near.org',
7
walletUrl: 'https://wallet.testnet.near.org',
8
appName: 'Paras Testnet',
9
contractName: `paras-token-v2.testnet`
10
}
11
12
try {
13
// Initializing nearAPI
14
// Login and init contract
15
const keyStore = new nearAPI.keyStores.UnencryptedFileSystemKeyStore(
16
`${process.env.HOME}/.near-credentials/`
17
)
18
19
const connection = await nearAPI.connect({
20
deps: {
21
keyStore: keyStore,
22
},
23
...config,
24
})
25
26
const account_id = 'orang.testnet'
27
const account = await connection.account(account_id)
28
29
const contract = await new nearAPI.Contract(
30
account,
31
config.contractName,
32
{
33
changeMethods: [
34
'nft_create_series'
35
],
36
}
37
)
38
39
const formattedParams = {
40
token_metadata: {
41
title: 'Dark',
42
media: 'bafybeifdbvb6yzajogbe4dbn3bgxoli3sp7ol7upfmu2givpvbwufydthu',
43
reference: 'bafybeifvzitvju4ftwnkf7w7yakz7i5colcey223uk2ui4t5z3ss7l2od4',
44
copies: 100
45
},
46
price: null,
47
royalty: {
48
[account_id]: 1000
49
}
50
}
51
52
const ret = await contract.nft_create_series(
53
formattedParams,
54
300000000000000, // attached GAS
55
"8540000000000000000000"
56
)
57
58
console.log(ret)
59
} catch (err) {
60
throw err
61
}
62
}
63
64
main()
Copied!