Quick Start
Get up and running with the Autonity SDK in minutes.
Installation
Install the Autonity SDK using your preferred package manager:
- npm
- yarn
- pnpm
npm install autonity-sdk
yarn add autonity-sdk
pnpm add autonity-sdk ethers
pnpm does not automatically install peer dependencies, so you also need to install ethers.
Basic Usage (View-only)
For read-only operations, you only need to provide the RPC URL and contract address:
import { Contract } from 'autonity-sdk';
// Create a contract instance (read-only)
const contract = new Contract({
rpcUrl: "https://rpc.autonity.org",
contractAddress: "0x..."
});
Using Private Key (Automatic Signer)
When you need to send transactions, provide your private key and the SDK will automatically create a signer:
import { Contract } from 'autonity-sdk';
// Create a contract instance with private key
const contract = new Contract({
rpcUrl: "https://rpc.autonity.org",
contractAddress: "0x...",
privateKey: "0xYOUR_PRIVATE_KEY"
});
Using Custom Signer
For advanced use cases, you can provide your own configured signer:
import { Contract } from 'autonity-sdk';
import { ethers } from 'ethers';
// Create a provider and signer
const provider = new ethers.JsonRpcProvider('https://rpc.autonity.org');
const signer = new ethers.Wallet('0xYOUR_PRIVATE_KEY', provider);
// Create a contract instance with custom signer
const contract = new Contract({
provider: provider,
contractAddress: '0x...',
signer: signer
});
Configuration Options
The SDK supports three different configuration modes depending on your use case:
View-only (read-only)
For applications that only need to read data from the blockchain:
Option | Type | Required | Description |
---|---|---|---|
rpcUrl | string | Yes | RPC endpoint URL for read-only operations |
contractAddress | string | Yes | Autonity contract address |
privateKey | string | No | Not used in read-only mode |
signer | ethers.Signer | No | Not used in read-only mode |
Using Private Key (automatic signer)
For applications that need to send transactions with automatic signer creation:
Option | Type | Required | Description |
---|---|---|---|
rpcUrl | string | Yes | RPC endpoint URL for sending transactions |
contractAddress | string | Yes | Autonity contract address |
privateKey | string | Yes | Private key used to create signer |
signer | ethers.Signer | No | Do not use together with privateKey |
Using Custom Signer
For applications with pre-configured signers or advanced signing requirements:
Option | Type | Required | Description |
---|---|---|---|
provider | ethers.Provider | Yes | Provider associated with the signer |
contractAddress | string | Yes | Autonity contract address |
signer | ethers.Signer | Yes | Pre-configured ethers signer for transactions |
rpcUrl | string | No | Optional if signer already has a provider |
privateKey | string | No | Do not use together with signer |