Consensus
Auto-Consensus Package Documentation
Introduction
The @autonomys/auto-consensus
package provides functions for interacting with the Consensus Layer of the Autonomys Network. It allows developers to perform actions such as account management, balance inquiries, transfers, staking operations, and more. This package works hand-in-hand with @autonomys/auto-utils
to simplify blockchain interactions.
Installation
Install the package via npm or yarn:
# Using npm
npm install @autonomys/auto-consensus
# Using yarn
yarn add @autonomys/auto-consensus
Importing the Package
Before using the functions provided by the auto-consensus
package, you need to import them into your project:
// Import specific functions
import { balance, transfer, account } from '@autonomys/auto-consensus';
// Or import everything
import * as consensus from '@autonomys/auto-consensus';
Overview of the api
Object
Many functions in the auto-consensus
package require an api
object as a parameter. This api
object is an instance of ApiPromise
from the Polkadot.js API library, which serves as the gateway to interact with the blockchain node.
Core Components of api
:
- api.rpc: Methods to perform remote procedure calls to the node.
- api.query: Access to the blockchain's runtime storage.
- api.tx: Create and submit extrinsics (transactions) to the blockchain.
- api.consts: Runtime constants defined in the blockchain's metadata.
- api.events: Access to events emitted by the blockchain.
- api.types: Type definitions used by the chain.
Example:
import { createConnection } from '@autonomys/auto-utils';
async function getApiInstance() {
const endpoint = 'wss://rpc-0.gemini-3h.subspace.network/ws';
const api = await createConnection(endpoint);
return api;
}