General Usage

Install

npm

Execute the following command to obtain the latest version of the JS-SDK:

npm i cess-js-sdk --save

or yarn

yarn add cess-js-sdk -S

Use

This is a example of an js-sdk instance:

/*
 * @Description: js-sdk for space demo
 * @Autor: cess lab
 */

const { Space, InitAPI, Common, testnetConfig, wellKnownAcct } = require("cess-js-sdk");

async function main() {
	const { api, keyring } = await InitAPI(testnetConfig);
	const { addr, mnemonic } = wellKnownAcct;

	const space = new Space(api, keyring);
	const common = new Common(api, keyring);

	console.log("query userOwnedSpace:");
	let result = await space.userOwnedSpace(addr);
	const blockHeight = await common.queryBlockHeight();

	result = common.formatSpaceInfo(result.data, blockHeight);
	console.log(result);

	function getDataIfOk(result) {
		return result.msg === "ok" ? result.data : result;
	}

	if (result.totalSpace) {
		console.log("expansionSpace:");
		result = await space.expansionSpace(mnemonic, 1);
		console.log(getDataIfOk(result), "\n");

		console.log("renewalSpace:");
		result = await space.renewalSpace(mnemonic, 1);
		console.log(getDataIfOk(result), "\n");
	} else {
		console.log("buySpace:");
		result = await space.buySpace(mnemonic, 1);
		console.log(getDataIfOk(result), "\n");
	}

	console.log("query userOwnedSpace:");
	result = await space.userOwnedSpace(addr);
	result = common.formatSpaceInfo(result.data, blockHeight);
	console.log(result);
}

main()
	.catch(console.error)
	.finally(() => process.exit());

CESS test network rpc endpoints

wss://testnet-rpc0.cess.cloud/ws/
wss://testnet-rpc1.cess.cloud/ws/
wss://testnet-rpc2.cess.cloud/ws/

CESS test network faucet

https://testnet-faucet.cess.cloud/

CESS test network public gateway

Address : https://deoss-pub-gateway.cess.cloud/
Account : cXhwBytXqrZLr1qM5NHJhCzEMckSTzNKw17ci2aHft6ETSQm9

Last updated