Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Commit 23a8c55

Browse files
committed
feat: integrates new chain-sdk into akashjs
1 parent c173459 commit 23a8c55

44 files changed

Lines changed: 1212 additions & 2942 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
MNEMONIC='<your wallet mnemonic>'
1+
MNEMONIC='<your wallet mnemonic>'
2+
RPC_ENDPOINT=https://rpc.sandbox-2.aksh.pw:443 # sandbox RPC node url (others - https://github.com/akash-network/net)

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
![build:main](https://github.com/ovrclk/akashjs/actions/workflows/release.yml/badge.svg?branch=main)
44

5+
**DEPRECATED:** akashjs examples are deprecated and won't be updated with the next network upgrade. Please switch to [chain-sdk](https://github.com/akash-network/chain-sdk/tree/main/ts) which provides more developer-friendly API with IDE autocomplete support
6+
7+
58
Connect and communicate with the Akash Network. Pure JS library can be used in browser for unsigned transactions, and with node.js for full compatibility.
69

710
## Packages
@@ -143,4 +146,3 @@ npm run setup-git-hooks
143146
- Set `DEBUG=akashjs:*` environment variable for detailed logs
144147

145148
PRs are welcome! By adhering to these guidelines and leveraging our automated systems, we can maintain a high-quality codebase and streamline our development processes.
146-

examples/README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# AkashJS Examples
22

3+
**DEPRECATED:** akashjs examples are deprecated and won't be updated with the next network upgrade. Please switch to [chain-sdk](https://github.com/akash-network/chain-sdk/tree/main/ts) which provides more developer-friendly API with IDE autocomplete support
4+
35
This directory contains several examples of how to interact with the Akash networking using AkashJS and CosmJS.
46

57
## Setup
@@ -62,13 +64,7 @@ Install the following dependencies for general usage and signing transactions wi
6264
npm i @akashnetwork/akash-api @akashnetwork/akashjs @cosmjs/stargate @cosmjs/proto-signing
6365
```
6466

65-
If you want to create wallets
66-
67-
```bash
68-
npm i @cosmjs/launchpad
69-
```
70-
71-
For [amino encoding](https://docs.cosmos.network/main/learn/advanced/encoding#encoding-1)
67+
If you want to create wallets with [amino encoding](https://docs.cosmos.network/main/learn/advanced/encoding#encoding-1)
7268

7369
```bash
7470
npm i @cosmjs/amino
@@ -81,7 +77,7 @@ The following code shows an example of the process for creating a new Akash wall
8177
A new wallet can be initialized by calling `Secp256k1HdWallet.generate` from @cosmjs/launchpad, and passing `{ prefix: "akash" }`.
8278

8379
```ts
84-
import { Secp256k1HdWallet } from "@cosmjs/launchpad";
80+
import { Secp256k1HdWallet } from "@cosmjs/amino";
8581

8682
// the first parameter for generate is the size of the mnemonic, default is 12
8783
const wallet = await Secp256k1HdWallet.generate(undefined, { prefix: "akash" });
@@ -90,7 +86,7 @@ const wallet = await Secp256k1HdWallet.generate(undefined, { prefix: "akash" });
9086
After the wallet is created, specific private/public key pairs are available via `getAccounts`.
9187

9288
```ts
93-
import { Secp256k1HdWallet } from "@cosmjs/launchpad";
89+
import { Secp256k1HdWallet } from "@cosmjs/amino";
9490

9591
const wallet = await Secp256k1HdWallet.generate(undefined, { prefix: "akash" });
9692

@@ -101,7 +97,7 @@ const [account] = await wallet.getAccounts();
10197
The account address, as well as its public key, are available as properties on this account object.
10298

10399
```ts
104-
import { Secp256k1HdWallet } from "@cosmjs/launchpad";
100+
import { Secp256k1HdWallet } from "@cosmjs/amino";
105101

106102
const wallet = await Secp256k1HdWallet.generate(undefined, { prefix: "akash" });
107103

@@ -116,7 +112,7 @@ const { address, pubkey } = account;
116112
Cosmjs does not publicly expose the private key for accounts. Instead, messages are passed into the wallet for signing. This can be done directly, as shown below.
117113

118114
```ts
119-
import { Secp256k1HdWallet, StdSignDoc } from "@cosmjs/launchpad";
115+
import { Secp256k1HdWallet, StdSignDoc } from "@cosmjs/amino";
120116

121117
function getMessage(): StdSignDoc {
122118
// implements custom message

examples/create_deployment.ts

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1+
/**
2+
* akashjs examples are working but deprecated.
3+
* PLEASE switch to chain-sdk which provides more developer-friendly API with IDE autocomplete support:
4+
* https://github.com/akash-network/chain-sdk/tree/main/ts
5+
*/
6+
17
import fs from "fs";
28
import path from "path";
39
import https from "https";
410
import { SigningStargateClient } from "@cosmjs/stargate";
5-
import { MsgCreateDeployment } from "@akashnetwork/akash-api/akash/deployment/v1beta3";
6-
import { QueryClientImpl as QueryProviderClient, QueryProviderRequest } from "@akashnetwork/akash-api/akash/provider/v1beta3";
7-
import { QueryBidsRequest, QueryClientImpl as QueryMarketClient, MsgCreateLease, BidID } from "@akashnetwork/akash-api/akash/market/v1beta4";
11+
import { MsgCreateDeployment, QueryProviderRequest, QueryProviderResponse } from "@akashnetwork/chain-sdk/private-types/akash.v1beta4";
12+
import { BidID, Source } from "@akashnetwork/chain-sdk/private-types/akash.v1";
13+
import { QueryBidsRequest, MsgCreateLease, QueryBidsResponse } from "@akashnetwork/chain-sdk/private-types/akash.v1beta5";
814
import * as cert from "@akashnetwork/akashjs/build/certificates";
915
import { getRpc } from "@akashnetwork/akashjs/build/rpc";
1016
import { SDL } from "@akashnetwork/akashjs/build/sdl";
1117
import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate";
1218
import { CertificatePem } from "@akashnetwork/akashjs/build/certificates/certificate-manager/CertificateManager";
1319
import { certificateManager } from "@akashnetwork/akashjs/build/certificates/certificate-manager";
1420
import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing";
15-
import dotenv from "dotenv";
16-
17-
dotenv.config({ path: "../.env" });
18-
19-
// In case you want to test on a sandbox environment, uncomment the following line and comment the following line
20-
// const rpcEndpoint = "https://rpc.sandbox-01.aksh.pw";
21+
import { createRpcRequest } from "./grpc_client";
22+
import { QueryInput } from "@akashnetwork/chain-sdk";
23+
import "./setup";
2124

22-
// Update this with your RPC endpoint
23-
const rpcEndpoint = "https://rpc.akashnet.net:443";
25+
const rpcEndpoint = process.env.RPC_ENDPOINT || "";
26+
if (!rpcEndpoint) {
27+
throw new Error("RPC_ENDPOINT environment variable is not set. Please set the environment variable in the .env file. See .env.sample for more information.");
28+
}
2429

2530
// Update this environment variable with your wallet mnemonic
2631
const mnemonic = process.env.MNEMONIC || "";
@@ -35,7 +40,7 @@ const certificatePath = path.resolve(__dirname, "./fixtures/cert.json");
3540
type Deployment = {
3641
id: {
3742
owner: string;
38-
dseq: number;
43+
dseq: number | string;
3944
};
4045
};
4146

@@ -91,6 +96,7 @@ async function loadOrCreateCertificate(wallet: DirectSecp256k1HdWallet, client:
9196
const accounts = await wallet.getAccounts();
9297
// check to see if we can load the certificate from the fixtures folder
9398

99+
console.log("Accounts:", accounts[0].address);
94100
if (fs.existsSync(certificatePath)) {
95101
return loadCertificate(certificatePath);
96102
}
@@ -142,15 +148,17 @@ async function createDeployment(sdl: SDL, wallet: DirectSecp256k1HdWallet, clien
142148
const deployment = {
143149
id: {
144150
owner: accounts[0].address,
145-
dseq: blockheight
151+
dseq: String(blockheight)
146152
},
147153
groups: groups,
148154
deposit: {
149-
denom: "uakt",
150-
amount: "5000000"
155+
sources: [Source.balance],
156+
amount: {
157+
denom: "uakt",
158+
amount: "5000000"
159+
},
151160
},
152-
version: await sdl.manifestVersion(),
153-
depositor: accounts[0].address
161+
hash: await sdl.manifestVersion(),
154162
};
155163

156164
const fee = {
@@ -164,7 +172,7 @@ async function createDeployment(sdl: SDL, wallet: DirectSecp256k1HdWallet, clien
164172
};
165173

166174
const msg = {
167-
typeUrl: "/akash.deployment.v1beta3.MsgCreateDeployment",
175+
typeUrl: `/${MsgCreateDeployment.$type}`,
168176
value: MsgCreateDeployment.fromPartial(deployment)
169177
};
170178

@@ -177,23 +185,29 @@ async function createDeployment(sdl: SDL, wallet: DirectSecp256k1HdWallet, clien
177185
throw new Error(`Could not create deployment: ${tx.rawLog} `);
178186
}
179187

180-
async function fetchBid(dseq: number, owner: string) {
188+
async function fetchBid(dseq: number | string, owner: string) {
181189
const rpc = await getRpc(rpcEndpoint);
182-
const client = new QueryMarketClient(rpc);
183-
const request = QueryBidsRequest.fromPartial({
190+
191+
const request: QueryInput<QueryBidsRequest> = {
184192
filters: {
185193
owner: owner,
186194
dseq: dseq
187195
}
188-
});
196+
};
189197

190198
const startTime = Date.now();
191199
const timeout = 1000 * 60 * 5;
192200

201+
const getBids = createRpcRequest(rpc, {
202+
methodName: "akash.market.v1beta5.Bids",
203+
requestType: QueryBidsRequest,
204+
responseType: QueryBidsResponse
205+
});
206+
193207
while (Date.now() - startTime < timeout) {
194208
console.log("Fetching bids...");
195209
await new Promise(resolve => setTimeout(resolve, 5000));
196-
const bids = await client.Bids(request);
210+
const bids = await getBids(request);
197211

198212
if (bids.bids.length > 0 && bids.bids[0].bid !== undefined) {
199213
console.log("Bid fetched!");
@@ -213,12 +227,12 @@ async function createLease(deployment: Deployment, wallet: DirectSecp256k1HdWall
213227
const bid = await fetchBid(dseq, owner);
214228
const accounts = await wallet.getAccounts();
215229

216-
if (bid.bidId === undefined) {
230+
if (bid.id === undefined) {
217231
throw new Error("Bid ID is undefined");
218232
}
219233

220234
const lease = {
221-
bidId: bid.bidId
235+
bidId: bid.id
222236
};
223237

224238
const fee = {
@@ -240,7 +254,7 @@ async function createLease(deployment: Deployment, wallet: DirectSecp256k1HdWall
240254

241255
if (tx.code !== undefined && tx.code === 0) {
242256
return {
243-
id: BidID.toJSON(bid.bidId) as {
257+
id: BidID.toJSON(bid.id) as {
244258
owner: string;
245259
dseq: number;
246260
provider: string;
@@ -308,26 +322,30 @@ async function sendManifest(sdl: SDL, lease: Lease, wallet: DirectSecp256k1HdWal
308322

309323
const { dseq, provider } = lease.id;
310324
const rpc = await getRpc(rpcEndpoint);
311-
const client = new QueryProviderClient(rpc);
312-
const request = QueryProviderRequest.fromPartial({
313-
owner: provider
325+
const getProvider = createRpcRequest(rpc, {
326+
methodName: "akash.provider.v1beta4.Provider",
327+
requestType: QueryProviderRequest,
328+
responseType: QueryProviderResponse
314329
});
315330

316-
const tx = await client.Provider(request);
331+
const providerResponse = await getProvider({
332+
owner: provider
333+
});
317334

318-
if (tx.provider === undefined) {
335+
if (providerResponse.provider === undefined) {
319336
throw new Error(`Could not find provider ${provider}`);
320337
}
321338

322-
const providerInfo = tx.provider;
339+
const providerInfo = providerResponse.provider;
323340
const manifest = sdl.manifestSortedJSON();
324341
const path = `/deployment/${dseq}/manifest`;
325342

326343
const uri = new URL(providerInfo.hostUri);
327344
const agent = new https.Agent({
328345
cert: certificate.cert,
329346
key: certificate.privateKey,
330-
rejectUnauthorized: false
347+
rejectUnauthorized: false,
348+
servername: "" // required to disable SNI, so the provider API will use mTLS authentication (e.i., self-signed certificates)
331349
});
332350

333351
await new Promise((resolve, reject) => {

examples/create_wallet.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Secp256k1HdWallet } from "@cosmjs/launchpad";
1+
/**
2+
* akashjs examples are working but deprecated.
3+
* PLEASE switch to chain-sdk which provides more developer-friendly API with IDE autocomplete support:
4+
* https://github.com/akash-network/chain-sdk/tree/main/ts
5+
*/
6+
7+
import { Secp256k1HdWallet } from "@cosmjs/amino";
28

39
async function main() {
410
const wallet = await Secp256k1HdWallet.generate(undefined, { prefix: "akash" });
Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1-
import { QueryClientImpl, QueryProviderRequest, QueryProviderResponse } from "@akashnetwork/akash-api/akash/provider/v1beta3";
1+
/**
2+
* akashjs examples are working but deprecated.
3+
* PLEASE switch to chain-sdk which provides more developer-friendly API with IDE autocomplete support:
4+
* https://github.com/akash-network/chain-sdk/tree/main/ts
5+
*/
6+
7+
import { QueryProviderRequest, QueryProviderResponse } from "@akashnetwork/chain-sdk/private-types/akash.v1beta4";
28
import { getRpc } from "@akashnetwork/akashjs/build/rpc";
9+
import { createRpcRequest } from "./grpc_client";
10+
import "./setup";
11+
12+
const rpcEndpoint = process.env.RPC_ENDPOINT || "";
13+
if (!rpcEndpoint) {
14+
throw new Error("RPC_ENDPOINT environment variable is not set. Please set the environment variable in the .env file. See .env.sample for more information.");
15+
}
16+
17+
if (!process.env.PROVIDER_ADDRESS) {
18+
throw new Error("PROVIDER_ADDRESS environment variable is not set.");
19+
}
320

421
async function main() {
5-
const client = new QueryClientImpl(await getRpc("http://rpc.akashnet.net"));
22+
const getProviderInfo = createRpcRequest(await getRpc(rpcEndpoint), {
23+
methodName: "akash.provider.v1beta4.Provider",
24+
requestType: QueryProviderRequest,
25+
responseType: QueryProviderResponse
26+
});
627

7-
const getProviderInfoRequest = QueryProviderRequest.fromPartial({
8-
owner: "akashSomeProviderAddress"
28+
const providerResponse = await getProviderInfo({
29+
owner: process.env.PROVIDER_ADDRESS
930
});
10-
const providerResponse = await client.Provider(getProviderInfoRequest);
11-
const data = QueryProviderResponse.toJSON(providerResponse);
1231

13-
console.log(data);
32+
console.log(providerResponse);
1433
}
1534

1635
main();

examples/estimate_gas.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,55 @@
1+
/**
2+
* akashjs examples are working but deprecated.
3+
* PLEASE switch to chain-sdk which provides more developer-friendly API with IDE autocomplete support:
4+
* https://github.com/akash-network/chain-sdk/tree/main/ts
5+
*/
6+
17
import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing";
28
import { SigningStargateClient } from "@cosmjs/stargate";
3-
import { MsgCloseDeployment } from "@akashnetwork/akash-api/akash/deployment/v1beta3";
9+
import { MsgCloseDeployment, QueryDeploymentsRequest, QueryDeploymentsResponse } from "@akashnetwork/chain-sdk/private-types/akash.v1beta4";
410
import { getAkashTypeRegistry, getTypeUrl } from "@akashnetwork/akashjs/build/stargate";
5-
import dotenv from "dotenv";
11+
import { createRpcRequest } from "./grpc_client";
12+
import { getRpc } from "../src/rpc";
13+
import "./setup";
14+
15+
// You can use your own RPC node, or get a list of public nodes from akashjs
16+
const rpcEndpoint = process.env.RPC_ENDPOINT || "";
17+
if (!rpcEndpoint) {
18+
throw new Error("RPC_ENDPOINT environment variable is not set. Please set the environment variable in the .env file. See .env.sample for more information.");
19+
}
620

7-
dotenv.config({ path: "../.env" });
21+
const mnemonic = process.env.MNEMONIC || "";
22+
if (!mnemonic) {
23+
throw new Error("MNEMONIC environment variable is not set. Please set the environment variable in the .env file. See .env.sample for more information.");
24+
}
825

926
async function main() {
10-
const mnemonic = process.env.MNEMONIC || "";
11-
if (!mnemonic) {
12-
throw new Error("MNEMONIC environment variable is not set. Please set the environment variable in the .env file. See .env.sample for more information.");
13-
}
1427
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: "akash" });
1528

1629
// get first account
1730
const [account] = await wallet.getAccounts();
1831

32+
const getDeployments = createRpcRequest(await getRpc(rpcEndpoint), {
33+
methodName: "akash.deployment.v1beta4.Deployments",
34+
requestType: QueryDeploymentsRequest,
35+
responseType: QueryDeploymentsResponse
36+
});
37+
38+
const {deployments} = await getDeployments({
39+
filters: {
40+
owner: account.address
41+
}
42+
});
43+
44+
if (deployments.length === 0) {
45+
throw new Error(`No deployments found for account: ${account.address}`);
46+
}
47+
const deployment = deployments[0];
48+
1949
// Use the encode method for the message to wrap the data
2050
const message = MsgCloseDeployment.fromPartial({
2151
id: {
22-
dseq: "555555",
52+
dseq: deployment.deployment?.id?.dseq?.toString() || "",
2353
owner: account.address
2454
}
2555
});
@@ -30,9 +60,6 @@ async function main() {
3060
value: message
3161
};
3262

33-
// You can use your own RPC node, or get a list of public nodes from akashjs
34-
const rpcEndpoint = "http://rpc.akashnet.net";
35-
3663
const myRegistry = new Registry(getAkashTypeRegistry());
3764

3865
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet, {

0 commit comments

Comments
 (0)