From ed5f566515e798591a470f05d90ce06fcb617ddb Mon Sep 17 00:00:00 2001 From: Greg Osuri Date: Mon, 9 Dec 2024 20:53:33 -0800 Subject: [PATCH] docs(readme): update README with detailed setup and contribution guidelines Enhanced the README with comprehensive instructions for development setup, including prerequisites and installation steps. Added detailed guidelines for contributing, covering TypeScript usage, testing, and code style. Included information on automated CI checks and the pull request process to ensure high code quality and consistency. --- README.md | 155 ++++-------------------------------------- examples/get_state.ts | 13 ++++ 2 files changed, 26 insertions(+), 142 deletions(-) create mode 100644 examples/get_state.ts diff --git a/README.md b/README.md index 3f93fe2..6b78ffe 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ This repository is the home of `akashjs`, a library designed to facilitate inter | Package | Description | | ------- | ----------- | | [@akashnetwork/akashjs](src) | Main library for interacting with the Akash Network | -| [@akashnetwork/akash-api](https://github.com/akash-network/akash-api/tree/main/ts) | Akash API generated from [Akash API](https://github.com/akash-network/akash-api) for interacting with the Akash Network. Documentation is available for [node](https://github.com/akash-network/akash-api/blob/main/docs/proto/node.md) and [provider](https://github.com/akash-network/akash-api/blob/main/docs/proto/provider.md) | -| [@cosmjs/stargate](https://github.com/cosmos/cosmjs/tree/main/packages/stargate) | A client library for the Cosmos SDK 0.40+ (Stargate) | -| [@cosmjs/proto-signing](https://github.com/cosmos/cosmjs/tree/main/packages/proto-signing) | A library for signing and broadcasting transactions using the Cosmos SDK | +| [@akashnetwork/akash-api](https://github.com/akash-network/akash-api/tree/main/ts) | Akash API generated from [Akash API](https://github.com/akash-network/akash-api) for interacting with the Akash Network. Documentation is available for [node](https://github.com/akash-network/akash-api/blob/main/docs/proto/node.md) and [provider](https://github.com/akash-network/akash-api/blob/main/docs/proto/provider.md). | +| [@cosmjs/stargate](https://github.com/cosmos/cosmjs/tree/main/packages/stargate) | A client library for the Cosmos SDK 0.40+ (Stargate). | +| [@cosmjs/proto-signing](https://github.com/cosmos/cosmjs/tree/main/packages/proto-signing) | A library for signing and broadcasting transactions using the Cosmos SDK. | ## Compatibility @@ -21,158 +21,29 @@ Compatible with modern browsers, nodejs 14+ and Webpack 5 ## Installation -Install from `npm` or `yarn`: +To install the library, run the following command: -```bash -npm i @akashnetwork/akashjs -yarn add @akashnetwork/akashjs +```sh +npm install @akashnetwork/akashjs ``` Or use the UMD bundle (the object returned is `Window.akjs`): ```html - -``` - -## Key Features - -### Certificate Management - -Generate, broadcast and manage certificates for the Akash Network: - -```typescript -import { certificate } from "@akashnetwork/akashjs"; - -// Generate a new certificate -const cert = await certificate.createCertificate("akash1..."); - -// Broadcast the certificate -await certificate.broadcastCertificate(cert, "akash1...", client); - -// Revoke a certificate -await certificate.revokeCertificate("akash1...", "serial123", client); - -// Query certificates -const certs = await certificate.queryCertificates({ - owner: "akash1..." -}); + ``` -### Network Interaction - -Connect to and interact with the Akash Network: +## Getting Started -```typescript -import { network, rpc } from "@akashnetwork/akashjs"; +The following example demonstrates how to fetch the state of the network. -// Get sorted RPC endpoints for mainnet -const endpoints = await network.getEndpointsSorted("mainnet", "rpc"); +```js +import { getMetadata } from "@akashnetwork/akashjs/build/network/index.js"; -// Get network metadata -const metadata = await network.getMetadata("mainnet"); +console.log(JSON.stringify(await getMetadata("mainnet"), null, 2)) ``` -### Wallet Integration - -Integrate with Keplr wallet and handle transactions: - -```typescript -import { keplr, wallet } from "@akashnetwork/akashjs"; - -// Get chains configuration -const chains = keplr.getChains(); - -// Get signer for a chain -const signer = keplr.getSigner(chains.mainnet); - -// Connect to a chain -const client = await keplr.get(chains.mainnet, signer, endpoint); -``` - -### Stargate Client - -For more control over transactions, use the Stargate client integration: - -```typescript -import { stargate as akashStargate } from "@akashnetwork/akashjs"; -import { Registry, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; -import { SigningStargateClient } from "@cosmjs/stargate"; - -// Setup registry -const myRegistry = new Registry([ - ...defaultRegistryTypes, - ...akashStargate.registry, -]); - -// Create client -const client = await SigningStargateClient.connectWithSigner( - `http://rpcUrl/`, - offlineSigner, - { - registry: myRegistry, - } -); -``` - -### Transaction Example - -Here's an example of sending a deployment take-down message: - -```typescript -const mnemonic = "your wallet mnemonic"; -const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: "akash" }); - -// Get first account -const [account] = await wallet.getAccounts(); - -// Create the message -const message = MsgCloseDeployment.fromPartial({ - id: { - dseq: "555555", - owner: account.address, - } -}); - -// Set the message type and value -const msgAny = { - typeUrl: getTypeUrl(MsgCloseDeployment), - value: message -}; - -// Setup client with registry -const myRegistry = new Registry(getAkashTypeRegistry()); -const client = await SigningStargateClient.connectWithSigner( - rpcEndpoint, - wallet, - { registry: myRegistry } -); - -// Define transaction fee -const fee = { - amount: [ - { - denom: "uakt", - amount: "5000", - }, - ], - gas: "800000", -}; - -// Sign and broadcast -const result = await client.signAndBroadcast( - account.address, - [msgAny], - fee, - "take down deployment" -); -``` - -## Examples - -Additional examples can be found in the [examples directory](examples) +More elborate examples can be found in the [examples](examples) directory. ## Contributing diff --git a/examples/get_state.ts b/examples/get_state.ts new file mode 100644 index 0000000..7e7a4d1 --- /dev/null +++ b/examples/get_state.ts @@ -0,0 +1,13 @@ +import { getMetadata } from "@akashnetwork/akashjs/build/network"; + +async function fetchMetadata() { + try { + console.log("Fetching metadata..."); + const metadata = await getMetadata("mainnet"); + console.log(JSON.stringify(metadata, null, 2)); + } catch (error) { + console.error("Error fetching metadata:", error); + } +} + +fetchMetadata(); \ No newline at end of file