AtomicAssets JavaScript
JS Library to read data from the atomicassets NFT standard.
Contract / General Documentation can be found on https://github.com/pinknetworkx/atomicassets-contracts/wiki
Usage
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm install atomicassets
Initialize
Web library can be found in the dist
folder
const {RpcApi} = require("atomicassets");
import {RpcApi} from "atomicassets"
const fetch = require("node-fetch");
const api = new RpcApi("https://testnet.wax.pink.gg", "atomicassets", {fetch, rateLimit: 4});
const asset = await api.getAsset("leonleonleon", "1099511627786");
const actions = api.action.mintasset(
[{actor: "pinknetworkx", permission: "active"}],
"collection", "scheme", -1, "pinknetworkx", {"name": "test"}, {"species": "test2"}
)
Serialization
AtomicAssets uses serialization to store data on the blockchain more efficiently.
The API classes will handle this for you but if you need to manually parse the data,
the library provides you a serialize and deserialize function
More information can be found here
import {serialize, deserialize, ObjectSchema} from "atomicassets"
const schema = ObjectSchema([
{"name": "attr1", "type": "int32"},
{"name": "attr2", "type": "uint32"},
{"name": "attr3", "type": "fixed32"},
{"name": "attr4", "type": "bool"},
{"name": "attr5", "type": "bytes"},
{"name": "attr6", "type": "string"},
{"name": "attr7", "type": "ipfs"},
{"name": "attr7", "type": "float"},
{"name": "attr9", "type": "double"},
{"name": "arr1", "type": "int32[]"},
]);
const rawObject = {
"attr1": -5843
};
const serializedData = serialize(rawObject, schema);
const deserializedData = deserialize(serializedData, schema);
Documentation
There are two methods available to fetch data from the blockchain.
- RpcAPI: uses only native nodeos calls
- ExplorerAPI: uses an hosted API which proves simple and fast REST API endpoints
RpcActionGenerator
Both APIs have a action
attribute which contains a helper class to construct contract actions
which can be pushed on chain with eosjs. See an example on top of the page.
Detailed information about each action can be found here
RpcApi
This api only uses native nodeos api calls to fetch data about NFTs.
It is recommended to use the Explorer API for production or applications which require fast load times.
Methods
Caching can be disabled by explicitly setting cache to false
async getAsset(owner: string, id: string, cache: boolean = true): Promise<RpcAsset>
- gets data about a specific asset owned by owner
async getTemplate(id: string, cache: boolean = true): Promise<RpcTemplate>
- gets a specific template by id
async getScheme(collection: string, name: string, cache: boolean = true): Promise<RpcScheme>
async getCollection(name: string, cache: boolean = true): Promise<RpcCollection>
async getCollectionTemplates(collection: string, cache: boolean = true): Promise<RpcTemplates[]>
- gets all templates of a collection
async getCollectionSchemes(collection: string, cache: boolean = true): Promise<RpcSchemes[]>
- gets all schemes of a collection
async getOffer(id: string, cache: boolean = true): Promise<RpcOffer>
async getAccountOffers(account: string, cache: boolean = true): Promise<RpcOffer[]>
- get all offers which are sent or received by an account
async getAccountAssets(account: string, cache: boolean = true): Promise<RpcAsset[]>
- gets the complete inventory of a specific account (may take long for bigger inventories)
Types
These classes represent table rows of the contract and consist of getter methods
which return the deserialized data.
The method toObject
returns a JavaScript object representation of the class.
RpcAsset
async collection(): Promise<RpcCollection>
async schema(): Promise<RpcSchema>
async template(): Promise<RpcTemplate | null>
async backedTokens(): Promise<string[]>
async immutableData(): Promise<object>
async mutableData(): Promise<object>
async data(): Promise<object>
async toObject(): Promise<object>
RpcTemplate
async collection(): Promise<RpcCollection>
async scheme(): Promise<RpcScheme>
async immutableData(): Promise<object>
async isTransferable(): Promise<boolean>
async isBurnable(): Promise<boolean>
async maxSupply(): Promise<number>
async circulation(): Promise<number>
async toObject(): Promise<object>
RpcSchema
async collection(): Promise<ISchema>
async format(): Promise<ISchema>
async toObject(): Promise<object>
RpcCollection
async author(): Promise<string>
async allowNotify(): Promise<boolean>
async authorizedAccounts(): Promise<string[]>
async notifyAccounts(): Promise<string[]>
async marketFee(): Promise<number>
async data(): Promise<any>
async toObject(): Promise<object>
RpcOffer
async sender(): Promise<string>
async recipient(): Promise<string>
async senderAssets(): Promise<Array<RpcAsset | string>>
- if element is a string, the asset is not owned by the sender anymore and the offer is invalid
async recipientAssets(): Promise<Array<RpcAsset | string>>
- if element is a string, the asset is not owned by the recipient anymore and the offer is invalid
async memo(): Promise<string>
async toObject(): Promise<object>
Explorer API
COMING SOON