Using near-api-js
Most of the examples provided will be shown in near-cli format, to make it easier for developers we also provided some near-api-js example to run some functions. Since some of them are not going to be shown with near-cli format, here is an example showing nft_create_series:
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!
Copy link