Skip to content

Instantly share code, notes, and snippets.

@hdriqi
Created March 5, 2021 00:32
Show Gist options
  • Save hdriqi/d3e599e925a3909b4d342a319dfe9d0b to your computer and use it in GitHub Desktop.
Save hdriqi/d3e599e925a3909b4d342a319dfe9d0b to your computer and use it in GitHub Desktop.
Check NFT Balance on Paras
const { keyStores, connect } = require('near-api-js')
const getConfig = (env, contractName) => {
if (!contractName) {
throw '[env] contractName not found'
}
switch (env) {
case 'mainnet':
return {
networkId: 'mainnet',
nodeUrl: 'https://rpc.mainnet.near.org',
contractName: contractName,
walletUrl: 'https://wallet.mainnet.near.org',
helperUrl: 'https://helper.mainnet.near.org',
}
case 'development':
case 'testnet':
return {
networkId: 'default',
nodeUrl: 'https://rpc.testnet.near.org',
contractName: contractName,
walletUrl: 'https://wallet.testnet.near.org',
helperUrl: 'https://helper.testnet.near.org',
}
case 'devnet':
return {
networkId: 'devnet',
nodeUrl: 'https://rpc.devnet.near.org',
contractName: contractName,
walletUrl: 'https://wallet.devnet.near.org',
helperUrl: 'https://helper.devnet.near.org',
}
case 'betanet':
return {
networkId: 'betanet',
nodeUrl: 'https://rpc.betanet.near.org',
contractName: contractName,
walletUrl: 'https://wallet.betanet.near.org',
helperUrl: 'https://helper.betanet.near.org',
}
case 'local':
return {
networkId: 'local',
nodeUrl: 'http://localhost:3030',
keyPath: `${process.env.HOME}/.near/validator_key.json`,
walletUrl: 'http://localhost:4000/wallet',
contractName: contractName,
}
case 'test':
case 'ci':
return {
networkId: 'shared-test',
nodeUrl: 'https://rpc.ci-testnet.near.org',
contractName: contractName,
masterAccount: 'test.near',
}
case 'ci-betanet':
return {
networkId: 'shared-test-staging',
nodeUrl: 'https://rpc.ci-betanet.near.org',
contractName: contractName,
masterAccount: 'test.near',
}
default:
throw Error(
`Unconfigured environment '${env}'. Can be configured in src/config.js.`
)
}
}
const main = async () => {
const keyStore = new keyStores.InMemoryKeyStore()
const config = getConfig('mainnet', 'contract.paras.near')
const near = await connect({
deps: {
keyStore: keyStore,
},
...config,
})
const masterAccount = await near.account(config.contractName)
const result = await masterAccount.viewFunction(
config.contractName,
'balanceOf',
{
ownerId: 'riqi.near',
tokenId: 'QmPxZfSvQNrhjoDeabdVBsDEeyS5zBm6zT4MdbdzhcC3Cf',
}
)
console.log(result)
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment