The Autonomys Auto SDK is a powerful toolkit designed to empower developers to seamlessly integrate with the Autonomys Network. It enables interaction through familiar programming languages like TypeScript, without needing to delve into the complexities of blockchain or smart contracts. The SDK provides simple APIs for issuing and verifying Auto IDs, interacting with the consensus layer, handling data uploads, and managing payments using Auto Coin.
This monorepo contains multiple packages, each serving a specific purpose. All packages are published to npm under the @autonomys
scope:
@autonomys/auto-utils
: Core utility functions for interacting with the Autonomys Network.@autonomys/auto-consensus
: Functions for interacting with the Consensus Layer.@autonomys/auto-dag-data
: Tools for preparing and managing data for on-chain storage.@autonomys/auto-id
: Functions for generating, renewing, and revoking Decentralized Identities (Auto IDs).@autonomys/auto-drive
: Tools for interacting with the Autonomys Auto-Drive API.
- Node.js (version 14 or higher)
- Yarn or npm
Install the packages you need via npm or yarn. For example, to install @autonomys/auto-utils
and @autonomys/auto-consensus
:
# Using npm
npm install @autonomys/auto-utils @autonomys/auto-consensus
# Using yarn
yarn add @autonomys/auto-utils @autonomys/auto-consensus
Below are small, reproducible examples demonstrating how to use each package. Packages are grouped where it makes sense to show how they interact.
These two packages work hand-in-hand to allow you to interact with the Autonomys Network and perform actions like checking balances and transferring funds.
// Import necessary functions
import { activateWallet } from '@autonomys/auto-utils'
import { balance } from '@autonomys/auto-consensus'
;(async () => {
// Activate a wallet using a mnemonic phrase
const { api, accounts } = await activateWallet({
mnemonic: 'your mnemonic phrase here', // Replace with your mnemonic
networkId: 'gemini-3h', // Optional: specify the network ID
})
const account = accounts[0]
console.log(`Connected with account address: ${account.address}`)
// Check the account balance
const accountBalance = await balance(api, account.address)
console.log(`Account balance: ${accountBalance.free}`)
// Disconnect when done
await api.disconnect()
})()
// Import necessary functions
import { activateWallet } from '@autonomys/auto-utils'
import { transfer } from '@autonomys/auto-consensus'
;(async () => {
// Activate sender's wallet
const senderWallet = await activateWallet({
mnemonic: 'sender mnemonic phrase', // Replace with sender's mnemonic
})
const sender = senderWallet.accounts[0]
// Activate receiver's wallet
const receiverWallet = await activateWallet({
mnemonic: 'receiver mnemonic phrase', // Replace with receiver's mnemonic
})
const receiver = receiverWallet.accounts[0]
// Transfer 1 ATC from sender to receiver
const amount = 1 // Amount in ATC
const transferTx = await transfer(senderWallet.api, receiver.address, amount)
// Sign and send the transaction
await transferTx.signAndSend(sender, ({ status, txHash, events }) => {
if (status.isInBlock) {
console.log(`Transaction included at blockHash ${status.asInBlock}`)
console.log(`Transaction hash: ${txHash}`)
} else if (status.isFinalized) {
console.log(`Transaction finalized at blockHash ${status.asFinalized}`)
}
})
// Disconnect when done
await senderWallet.api.disconnect()
await receiverWallet.api.disconnect()
})()
The @autonomys/auto-dag-data
package provides utilities for creating and managing IPLD DAGs (InterPlanetary Linked Data Directed Acyclic Graphs) for files and folders.
// Import necessary functions
import { createFileIPLDDag } from '@autonomys/auto-dag-data'
import fs from 'fs'
const fileBuffer = fs.readFileSync('path/to/your/file.txt')
// Create an IPLD DAG from the file data
const dag = createFileIPLDDag(fileBuffer, 'file.txt')
console.log(`Created DAG with head CID: ${dag.headCID}`)
// The 'nodes' map contains all nodes in the DAG
console.log(`Total nodes in DAG: ${dag.nodes.size}`)
// Import necessary functions
import { createFolderIPLDDag } from '@autonomys/auto-dag-data'
import { CID } from 'multiformats'
import fs from 'fs'
import path from 'path'
// Function to read files from a directory and create CIDs
function getFilesCIDs(directoryPath: string): CID[] {
const fileNames = fs.readdirSync(directoryPath)
const cids: CID[] = []
fileNames.forEach((fileName) => {
const filePath = path.join(directoryPath, fileName)
const fileBuffer = fs.readFileSync(filePath)
const fileDag = createFileIPLDDag(fileBuffer, fileName)
cids.push(fileDag.headCID)
})
return cids
}
const directoryPath = 'path/to/your/folder'
const childCIDs = getFilesCIDs(directoryPath)
const folderName = 'my-folder'
const folderSize = childCIDs.length
// Create an IPLD DAG for the folder
const folderDag = createFolderIPLDDag(childCIDs, folderName, folderSize)
console.log(`Created folder DAG with head CID: ${folderDag.headCID}`)
The @autonomys/auto-id
package provides functionalities for managing certificates, authenticating users, and integrating Zero-Knowledge Proofs (ZKPs) on the Autonomys Network.
// Import necessary functions
import { authenticateAutoIdUser } from '@autonomys/auto-id'
import { activate } from '@autonomys/auto-utils'
;(async () => {
// Activate the network API
const api = await activate()
// User's Auto ID
const autoId = 'user-auto-id' // Replace with the user's Auto ID
// Challenge message that the user needs to sign
const challengeMessage = 'Please sign this message to authenticate.'
const challenge = new TextEncoder().encode(challengeMessage)
// Assume the user provides the signature
const signature = new Uint8Array([...]) // User's signature as Uint8Array
// Authenticate the user
const isAuthenticated = await authenticateAutoIdUser(api, autoId, challenge, signature)
if (isAuthenticated) {
console.log('User authenticated successfully.')
} else {
console.log('Authentication failed.')
}
// Disconnect when done
await api.disconnect()
})()
// Import necessary functions
import { selfIssueCertificate } from '@autonomys/auto-id'
import { generateKeyPair } from '@autonomys/auto-utils'
;(async () => {
// Generate a key pair
const keyPair = await generateKeyPair()
// Subject name for the certificate
const subjectName = 'CN=User Name' // Replace with appropriate subject
// Generate a self-signed certificate
const certificate = await selfIssueCertificate(subjectName, keyPair)
console.log('Certificate created:', certificate)
})()
If you wish to contribute or work on the SDK locally, follow the steps below to set up your development environment.
- Node.js (version 14 or higher)
- Yarn (version 1.22 or higher)
- Git
-
Clone the repository:
git clone https://github.com/autonomys/auto-sdk.git
-
Navigate to the project directory:
cd auto-sdk
-
Install Yarn 4 (Berry):
The project uses Yarn 4 for monorepo management.
yarn set version berry
-
Install dependencies:
yarn install
-
Build all packages:
yarn build
-
Run tests for all packages:
yarn test
To run tests for a specific package, navigate to the package directory and run the tests. For example, to run tests for auto-utils
:
cd packages/auto-utils
yarn test
During development, you might want to test changes across packages. To do this, you can use Yarn workspaces which are already set up in this monorepo. Changes in one package will be reflected in dependencies within the monorepo.
Ensure your code adheres to the project's linting and formatting standards:
# Check for linting errors
yarn lint
# Automatically fix linting errors
yarn lint:fix
# Format code with Prettier
yarn format
We follow the Conventional Commits specification for commit messages:
feat
: A new featurefix
: A bug fixdocs
: Documentation changesstyle
: Code style changes (formatting, missing semi-colons, etc.)refactor
: Code changes that neither fix a bug nor add a featuretest
: Adding or updating testschore
: Changes to the build process or auxiliary tools
Example commit message:
feat(auto-utils): add new function to handle network connections
We welcome community contributions! Here's how you can help:
-
Fork the repository on GitHub.
-
Clone your forked repository locally:
git clone https://github.com/your-username/auto-sdk.git cd auto-sdk
-
Create a new branch for your feature or bug fix:
git checkout -b feature/your-feature-name
-
Make your changes in the codebase.
-
Commit your changes following our commit message guidelines.
-
Push your changes to your forked repository:
git push origin feature/your-feature-name
-
Open a Pull Request against the
main
branch of the original repository.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
If you encounter any problems or have suggestions, please open an issue. Provide as much detail as possible to help us understand and address the issue.
If you need assistance, feel free to reach out by opening an issue or joining our community discussions.
- Autonomys Academy: Learn more about the Auto SDK and the vision behind it at Autonomys Academy.
This project is licensed under the MIT License. See the LICENSE file for details.
If you have any questions or need support, feel free to reach out:
- GitHub Issues: GitHub Issues Page
We appreciate your feedback and contributions!