for node version 17, need to do
export NODE_OPTIONS=--openssl-legacy-provider
to fixerror:03000086:digital envelope routines::initialization error
npm i --save tw-bc-group/irita-sdk-js
The SDK requires you to create your own key DAO implementation. The following example is a simple in-memory implementation:
import { Key, KeyDAO } from "@irita/irita-sdk";
export class CacheKeyDAOImpl implements KeyDAO {
private map: {[key: string]: object};
constructor() {
this.map = {};
}
write(name: string, key: Key): void {
this.map[name] = key;
}
read(name: string): Key {
return this.map[name];
}
delete(name: string): void {
delete this.map[name];
}
}
This should make you able to connect to the test network of wenchang chain.
import { newClient, CLIENT } from "@irita/irita-sdk";
const config = {
node: "http://47.100.192.234:26657",
chainId: "testing",
keyDAO: new KeyDAOImpl(),
};
const client: Client = newClient(config);
const key = client.keys.recover('tester', password, "opera vivid pride shallow brick crew found resist decade neck expect apple chalk belt sick author know try tank detail tree impact hand best", PubkeyType.sm2);
For other configurations please refer to ClientConfig
import { PubkeyType } from "@irita/irita-sdk";
const key = client.keys.add(name, password, PubkeyType.sm2);
console.log(key.address, key.mnemonic);
import { PubkeyType } from "@irita/irita-sdk";
const key = client.keys.recover(name, password, mnemonic, PubkeyType.sm2);
const denomId = `denomid${Math.floor(Math.random() * 1000000)}`;
const denomName = `Denom name ${Math.floor(Math.random() * 10000000)}`;
const schema = "no schema";
client.nft.issueDenom(denomId, denomName, schema, tx);
const tx = {
from: "tester",
password: "your password for the key",
pubkeyType: PubkeyType.sm2,
fee: {
denom: "ugas",
amount: "200000",
},
};
const nftId = `nftid${Math.floor(Math.random() * 1000000)}`;
const nftName = `NFT name ${Math.floor(Math.random() * 10000000)}`;
client.nft.mintNft(nftId, denomId, nftName, uri, data, receipient, tx);
const newProperty: {name?: string, uri?: string, data?: string} = {};
client.nft.editNft(denomId, nftId, newProperty, tx);
const newProperty: {name?: string, uri?: string, data?: string} = {};
const key2 = client.keys.add("tester2", password, PubkeyType.sm2);
client.nft.transferNft(nftId, denomId, client.keys.show("tester2"), newProperty, tx);
client.nft.burnNft(nftId, denomId, tx);
client.nft.queryDenoms();
client.nft.queryDenom(denomId);
client.nft.queryCollection(denomId);
client.nft.queryOwner(client.keys.show("tester"));
client.nft.queryNFT(denomId, nftId);
client.nft.querySupply(denomId, owner);