Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@unique-nft/sdk
Advanced tools
This package is a thin client for Unique Network. It is a wrapper around the Substrate RPC API that provides a more convenient API for interacting with Unique Network.
This package is a thin client for Unique Network. It is a wrapper around the Substrate RPC API that provides a more convenient API for interacting with Unique Network.
You can read more about working with SDK and Unique Network in the official documentation
npm install @unique-nft/sdk
To establish a connection, you may use one of the publicly available endpoints:
Network | Endpoint |
---|---|
Unique | https://rest.unique.network/v2/unique |
Quartz | https://rest.unique.network/v2/quartz |
Opal | https://rest.unique.network/v2/opal |
import { UniqueChain } from '@unique-nft/sdk'
import { Sr25519Account } from '@unique-nft/utils/sr25519'
// Create an account from a mnemonic
const account = Sr25519Account.fromUri('your mnemonic phrase here')
// Initialize UniqueChain with the account
const uniqueChain = UniqueChain({baseUrl: 'https://rest.unique.network/v2/opal'})
Retrieve the balance details of a specific account.
const balance = await uniqueChain.balance.get({ address: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" })
Transfer a specified amount from one account to another. The SDK supports transferring amounts in both Wei (smallest unit) and Coin (standard unit).
Transfer balance in wei:
const transferResult = await uniqueChain.balance.transfer(
{
to: toAddress,
amount, // Amount in Wei
},
{ signerAddress: fromAddress },
aliceAccount, // Signer account
)
Transfer Balance in coins:
const transferResult = await uniqueChain.balance.transfer(
{
to: toAddress,
amount, // Amount in Coins
isAmountInCoins: true,
},
{ signerAddress: fromAddress },
aliceAccount, // Signer account
)
Create a new collection on the Unique Network. Collections can be used to group related NFTs.
const collectionResult = await uniqueChain.collection.create({
mode: 'Nft',
name: 'My Collection',
description: 'A description for my collection',
symbol: 'MC',
info: {
cover_image: { url: 'https://ipfs.unique.network/ipfs/Qmau5RNqJMf6bR5mcatnAZGaF1hhiCY1UoaFctfw7rMhTU' },
},
})
Mint new NFTs within a specific collection.
const mintResult = await uniqueChain.token.mintNFTs({
collectionId,
tokens: [
{
data: {
image: 'https://ipfs.unique.network/ipfs/QmRJYgnXfo9WfTckYk8J1h4NTC35VBBGLsjhpkkFDuzQ9L',
attributes: [{ trait_type: 'Power', value: '10' }],
},
owner: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
},
{
data: {
image: 'https://ipfs.unique.network/ipfs/QmduruSNgY9h13p2q6hnsaot9vgVxYVzg9DL7ZWxZ6U5w6',
attributes: [{ trait_type: 'Speed', value: '8' }],
},
owner: '5H5ymQAo198Ap2rVGG7mNfAVkomFG98FdwL4mz8XqAJeGHHt',
},
],
})
Transfer ownership of an NFT from one account to another.
const transferResult = await uniqueChain.token.transfer(
{
to: '5H5ymQAo198Ap2rVGG7mNfAVkomFG98FdwL4mz8XqAJeGHHt',
collectionId: 1,
tokenId: 1,
},
{ signer: alice },
)
Modify the attributes or image of an existing NFT.
const updateResult = await uniqueChain.token.updateNft({
collectionId: 1,
tokenId: 1,
data: {
attributes: [{ trait_type: 'Power', value: '15' }],
image: 'https://ipfs.unique.network/ipfs/QmNewImageURL',
},
})
Remove an NFT permanently from the collection.
const burnResult = await uniqueChain.token.burn({
collectionId: 1,
tokenId: 2,
})
Nest one NFT within another, allowing for hierarchical ownership structures.
const parent = { collectionId: 1, tokenId: 1 }
const nested = { collectionId: 1, tokenId: 2 }
const nestResult = await uniqueChain.token.nest({
parent,
nested,
})
Authorize another account to manage or transfer your NFTs.
const approveResult = await uniqueChain.token.approve({
spender: '5H5ymQAo198Ap2rVGG7mNfAVkomFG98FdwL4mz8XqAJeGHHt',
collectionId: 1,
tokenId: 1,
})
const isApproved = await uniqueChain.token.getApproved({
collectionId: 1,
tokenId: 1,
spender: '5H5ymQAo198Ap2rVGG7mNfAVkomFG98FdwL4mz8XqAJeGHHt',
})
The Unique Network SDK provides robust methods to manage EVM-compatible contracts, including deploying contracts, interacting with them, and handling NFT collections within the EVM environment. Below are the key functionalities and how to use them.
Read more about how Substrate accounts work with EVM in the documentation.
Create a new NFT collection using the EVM-compatible methods.
const collectionCreationFee = await uniqueChain.evm.collectionHelpers.call({
functionName: 'collectionCreationFee',
functionArgs: [],
})
console.log('Collection Creation Fee:', collectionCreationFee)
const collectionResult = await uniqueChain.evm.collectionHelpers.send({
functionName: 'createNFTCollection',
functionArgs: ['Test Collection', 'Description of Test Collection', 'TC'],
value: collectionCreationFee, // Ensure to send the required fee
})
Deploy EVM-compatible smart contracts and interact with their functions seamlessly using the SDK.
const abi = [
{
"inputs": [
{
"internalType": "uint256",
"name": "num",
"type": "uint256"
}
],
"name": "store",
},
//...
]
const deployResult = await uniqueChain.evm.deploy({
bytecode: storageArtifacts.bytecode,
})
const contractAddress = deployResult.result.contractAddress
console.log('Contract Deployed at:', contractAddress)
// Verify the contract exists
const { exists } = await uniqueChain.evm.contractExists({ address: contractAddress })
console.log('Contract Exists:', exists)
// Interact with the contract's `store` function
const storeTx = await uniqueChain.evm.send({
functionName: 'store',
functionArgs: [123n],
contract: {
address: contractAddress,
abi,
},
})
The Unique Network SDK includes a typed wrapper around Axios to interact seamlessly with the Unique Network blockchain indexer API. This allows you to fetch and query blockchain data efficiently.
You can read more about working with Indexer and Unique Network in the official documentation
Network | Endpoint URL |
---|---|
Unique | https://api-unique.uniquescan.io/v2 |
Quartz | https://api-quartz.uniquescan.io/v2 |
Initialize the UniqueIndexer client with the desired base URL to start interacting with the blockchain indexer API.
import { UniqueIndexer } from '@unique-nft/sdk';
const indexerClient = UniqueIndexer({ baseUrl: 'https://api-unique.uniquescan.io/v2' });
Retrieve the latest 5 blocks in descending order by block number.
const blocks = await indexerClient.blocks({ limit: 5, orderByNumber: 'desc' });
Retrieve collections based on various search criteria like name, description, admin, owner, and sponsor.
const collections = await indexerClient.collections({
nameLike: '%substra%',
descriptionLike: '%First NFT collection%',
adminIn: ['5F6TPxrxZBhhpvRA8Lu1PWjcpoeoEkAQ4TVALpaxgenTU3sM'],
ownerIn: ['5H684Wa69GpbgwQ7w9nZyzVpDmEDCTexhRNmZ7mkqM1Rt7dH'],
sponsorIn: ['5H684Wa69GpbgwQ7w9nZyzVpDmEDCTexhRNmZ7mkqM1Rt7dH'],
isBurned: false,
orderByCollectionId: 'asc',
orderByName: 'asc',
});
Retrieve NFTs based on criteria such as collection ID, token ID, ownership, royalty recipients, and attributes.
const nfts = await indexerClient.nfts({
collectionIdIn: ['1', '0x17C4e6453cC49AAaaEaCA894E6D9683e00000001'],
tokenIdIn: [1],
isBurned: false,
royaltyRecipientIn: ['5Gus5r7HSZv9ScdaTNVbFMBEsxMtc4cZBPTLfJJbLXQK8m9d'],
attributeTraitTypeIn: ['traits'],
attributeValueIn: ['Up Hair', 'Teeth Smile'],
isBundle: false,
ownerIn: ['5FZeTmbZQZsJcyEevjGVK1HHkcKfWBYxWpbgEffQ2M1SqAnP'],
orderByTokenId: 'asc',
});
FAQs
This package is a thin client for Unique Network. It is a wrapper around the Substrate RPC API that provides a more convenient API for interacting with Unique Network.
We found that @unique-nft/sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.