Skip to content

Commit

Permalink
docs(readme): update README with detailed setup and contribution guid…
Browse files Browse the repository at this point in the history
…elines

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.
  • Loading branch information
gosuri committed Dec 10, 2024
1 parent ae59c43 commit ed5f566
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 142 deletions.
155 changes: 13 additions & 142 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,168 +11,39 @@ 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

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
<script
type="text/javascript"
src="https://unpkg.com/@akashnetwork/[email protected]/umd/akashjs.js"
></script>
```

## 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..."
});
<script type="text/javascript" src="https://unpkg.com/@akashnetwork/[email protected]/umd/akashjs.js" ></script>
```

### 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

Expand Down
13 changes: 13 additions & 0 deletions examples/get_state.ts
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit ed5f566

Please sign in to comment.