LogoLogo
  • Welcome to DeOSS Guide !
  • Introduction
    • Terminologies
    • System Architecture
    • Data Access Process
  • Product Pricing
  • Get Started
    • Configure CESS Account
    • DeOSS Gateway
      • Set up your Own Gateway
      • Step 1: Create a Bucket
      • Step 2: Upload an Object
      • Step 3: Download an Object
      • Step 4: Delete the Object and Buckets
    • GO-SDK
      • Preface
      • Initialize SDK
      • SDK client properties
        • View signature account
        • View the public key of the signing account
        • Check the connected RPC address
        • View sdk name
        • View signature account mnemonic phrase
      • File operation related
        • Storage space operations related
          • Buy space
          • Expansion space
          • Renewal space
          • Authorized space
          • Cancel authorization space
        • Bucket creation
        • Upload local file
        • Upload object
        • Upload file stream
        • File download
        • File delete
        • File encryption
        • File decryption
        • File specification processing
      • Chain operation related
        • Chain status
          • View DeOSS list
          • View all storage node accounts
          • View storage node details
          • View user space details
          • View account details
          • View token symbols
          • View block synchronization information
          • View chain version number
        • Chain transaction
          • Create storage order
          • Transfer
    • JS-SDK
      • General Usage
      • Bucket Operation
      • File Operation
      • Space Operation
      • Auth Operation
      • API library
    • Rust-SDK
      • Initialize SDK
      • Buy Space
      • Authorize Space
      • Bucket Creation
      • File Upload
      • File Download
      • File Encryption
      • File Decryption
  • API Reference
    • Introduction
    • Identity signature
    • Working with Objects
      • PutObject
      • GetObject
      • DeleteObject
      • GetObjectInfo
    • Working with Buckets
      • PutBucket
      • GetBucket
      • DeleteBucket
      • ListBucket
Powered by GitBook
On this page
  1. Get Started
  2. JS-SDK

Space Operation

The following is a example of Space operation:

/*
 * @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());
PreviousFile OperationNextAuth Operation

Last updated 1 year ago