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

Commit f73bc10

Browse files
committed
chore(examples): make sure create_deployment.ts example work
Also update types in other examples refs akash-network/akashjs#184
1 parent 733e73e commit f73bc10

15 files changed

Lines changed: 240 additions & 181 deletions

‎.commitlintrc.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": ["@commitlint/config-conventional"],
33
"rules": {
4-
"scope-enum": [2, "always", ["certificates", "network", "wallet", "api", "stargate", "sdl"]]
4+
"scope-enum": [2, "always", ["certificates", "network", "wallet", "api", "stargate", "sdl", "examples"]]
55
}
66
}

‎examples/README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,13 @@ When sending transactions, it can be useful to get an estimate of the gas requir
273273
);
274274

275275
console.log(gas);
276+
```
277+
278+
## Running an example
279+
280+
To run an example, you need to make the required changes to the code and use typescript compiler. You can use the following command to run the example. E.g. to run the `create_deployment.ts` example:
281+
282+
```bash
283+
cd examples
284+
ts-node -r tsconfig-paths/register create_deployment.ts
276285
```

‎examples/create_deployment.ts‎

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import fs from "fs";
2+
import path from "path";
23
import https from "https";
3-
44
import { SigningStargateClient } from "@cosmjs/stargate";
55
import { DirectSecp256k1HdWallet, Registry } from "cosmwasm";
6-
7-
// these imports should point to @akashnetwork/akashjs node module in your project
8-
import * as cert from "../build/certificates";
9-
import { getRpc } from "../build/rpc";
10-
import { SDL } from "../build/sdl";
11-
import { getAkashTypeRegistry } from "../build/stargate";
12-
import { QueryBidsRequest, QueryClientImpl as QueryMarketClient } from "../build/protobuf/akash/market/v1beta4/query";
13-
import { QueryClientImpl as QueryProviderClient, QueryProviderRequest } from "../build/protobuf/akash/provider/v1beta3/query";
14-
import { MsgCreateDeployment } from "../build/protobuf/akash/deployment/v1beta3/deploymentmsg";
15-
import { MsgCreateLease } from "../build/protobuf/akash/market/v1beta4/lease";
16-
import { BidID } from "../build/protobuf/akash/market/v1beta4/bid";
6+
import { MsgCreateDeployment } from "@akashnetwork/akash-api/akash/deployment/v1beta3";
7+
import { QueryClientImpl as QueryProviderClient, QueryProviderRequest } from "@akashnetwork/akash-api/akash/provider/v1beta3";
8+
import { QueryBidsRequest, QueryClientImpl as QueryMarketClient, MsgCreateLease, BidID } from "@akashnetwork/akash-api/akash/market/v1beta4";
9+
import * as cert from "@akashnetwork/akashjs/build/certificates";
10+
import { getRpc } from "@akashnetwork/akashjs/build/rpc";
11+
import { SDL } from "@akashnetwork/akashjs/build/sdl";
12+
import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate";
13+
import { CertificatePem } from "@akashnetwork/akashjs/build/certificates/certificate-manager/CertificateManager";
14+
import { certificateManager } from "@akashnetwork/akashjs/build/certificates/certificate-manager";
1715

1816
// update this with your wallet mnemonic
19-
const rpcEndpoint = "https://rpc.akashnet.net:443";
20-
const mnemonic = fs.readFileSync("./fixtures/mnemonic.txt", "utf8").trim();
21-
const rawSDL = fs.readFileSync("./fixtures/example.sdl.yaml", "utf8");
22-
const certificatePath = "./fixtures/cert.json";
17+
const rpcEndpoint = "https://rpc.sandbox-01.aksh.pw";
18+
// const rpcEndpoint = "https://rpc.akashnet.net:443";
19+
const mnemonic = fs.readFileSync(path.resolve(__dirname, "./fixtures/mnemonic.txt"), "utf8").trim();
20+
const rawSDL = fs.readFileSync(path.resolve(__dirname, "./fixtures/example.sdl.yaml"), "utf8");
21+
const certificatePath = path.resolve(__dirname, "./fixtures/cert.json");
2322

2423
type Deployment = {
2524
id: {
@@ -38,12 +37,6 @@ type Lease = {
3837
};
3938
};
4039

41-
type Certificate = {
42-
csr: string;
43-
privateKey: string;
44-
publicKey: string;
45-
};
46-
4740
// you can set this to a specific deployment sequence number to skip the deployment creation
4841
const dseq = 0;
4942

@@ -67,12 +60,12 @@ async function loadPrerequisites() {
6760
}
6861

6962
// saves the certificate into the fixtures folder
70-
function saveCertificate(certificate: { privateKey: string; publicKey: string; csr: string }) {
63+
function saveCertificate(certificate: CertificatePem) {
7164
const json = JSON.stringify(certificate);
7265
fs.writeFileSync(certificatePath, json);
7366
}
7467

75-
function loadCertificate(path: string): { csr: string; privateKey: string; publicKey: string } {
68+
function loadCertificate(path: string): CertificatePem {
7669
const json = fs.readFileSync(path, "utf8");
7770

7871
try {
@@ -91,7 +84,7 @@ async function loadOrCreateCertificate(wallet: DirectSecp256k1HdWallet, client:
9184
}
9285

9386
// if not, create a new one
94-
const certificate = await cert.createCertificate(accounts[0].address);
87+
const certificate = certificateManager.generatePEM(accounts[0].address);
9588
const result = await cert.broadcastCertificate(certificate, accounts[0].address, client);
9689

9790
if (result.code !== undefined && result.code === 0) {
@@ -104,7 +97,12 @@ async function loadOrCreateCertificate(wallet: DirectSecp256k1HdWallet, client:
10497
}
10598

10699
async function walletFromMnemonic(mnemonic: string) {
107-
return DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: "akash" });
100+
try {
101+
return await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: "akash" });
102+
} catch (error) {
103+
console.error('Could not create wallet from mnemonic, have you updated "examples/fixtures/mnemonic.txt?"');
104+
throw error;
105+
}
108106
}
109107

110108
async function createDeployment(sdl: SDL, wallet: DirectSecp256k1HdWallet, client: SigningStargateClient) {
@@ -243,7 +241,7 @@ async function createLease(deployment: Deployment, wallet: DirectSecp256k1HdWall
243241
throw new Error(`Could not create lease: ${tx.rawLog} `);
244242
}
245243

246-
async function queryLeaseStatus(lease: Lease, providerUri: string, certificate: Certificate) {
244+
async function queryLeaseStatus(lease: Lease, providerUri: string, certificate: CertificatePem) {
247245
const id = lease.id;
248246

249247
if (id === undefined) {
@@ -253,7 +251,7 @@ async function queryLeaseStatus(lease: Lease, providerUri: string, certificate:
253251
const leasePath = `/lease/${id.dseq}/${id.gseq}/${id.oseq}/status`;
254252

255253
const agent = new https.Agent({
256-
cert: certificate.csr,
254+
cert: certificate.cert,
257255
key: certificate.privateKey,
258256
rejectUnauthorized: false
259257
});
@@ -290,7 +288,7 @@ async function queryLeaseStatus(lease: Lease, providerUri: string, certificate:
290288
});
291289
}
292290

293-
async function sendManifest(sdl: SDL, lease: Lease, wallet: DirectSecp256k1HdWallet, certificate: { csr: string; privateKey: string; publicKey: string }) {
291+
async function sendManifest(sdl: SDL, lease: Lease, wallet: DirectSecp256k1HdWallet, certificate: { cert: string; privateKey: string; publicKey: string }) {
294292
if (lease.id === undefined) {
295293
throw new Error("Lease ID is undefined");
296294
}
@@ -314,7 +312,7 @@ async function sendManifest(sdl: SDL, lease: Lease, wallet: DirectSecp256k1HdWal
314312

315313
const uri = new URL(providerInfo.hostUri);
316314
const agent = new https.Agent({
317-
cert: certificate.csr,
315+
cert: certificate.cert,
318316
key: certificate.privateKey,
319317
rejectUnauthorized: false
320318
});

‎examples/details_of_single_provider.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QueryClientImpl, QueryProviderRequest, QueryProviderResponse } from "@akashnetwork/akashjs/build/protobuf/akash/provider/v1beta3/query";
1+
import { QueryClientImpl, QueryProviderRequest, QueryProviderResponse } from "@akashnetwork/akash-api/akash/provider/v1beta3";
22
import { getRpc } from "@akashnetwork/akashjs/build/rpc";
33

44
async function main() {

‎examples/estimate_gas.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing";
22
import { SigningStargateClient } from "@cosmjs/stargate";
3-
4-
// import the required message type from akashjs
5-
import { getAkashTypeRegistry, getTypeUrl } from "@akashnetwork/akashjs/build/stargate/index";
6-
import { MsgCloseDeployment } from "@akashnetwork/akashjs/build/protobuf/akash/deployment/v1beta3/deploymentmsg";
3+
import { MsgCloseDeployment } from "@akashnetwork/akash-api/akash/deployment/v1beta3";
4+
import { getAkashTypeRegistry, getTypeUrl } from "@akashnetwork/akashjs/build/stargate";
75

86
async function main() {
97
const mnemonic = "your wallet mnemonic";

‎examples/fixtures/example.sdl.yaml‎

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,58 @@
1-
version: '2.0'
1+
# Welcome to the Akash Network! 🚀☁
2+
# This file is called a Stack Definition Laguage (SDL)
3+
# SDL is a human friendly data standard for declaring deployment attributes.
4+
# The SDL file is a "form" to request resources from the Network.
5+
# SDL is compatible with the YAML standard and similar to Docker Compose files.
6+
7+
---
8+
# Indicates version of Akash configuration file. Currently only "2.0" is accepted.
9+
version: "2.0"
10+
11+
# The top-level services entry contains a map of workloads to be ran on the Akash deployment. Each key is a service name; values are a map containing the following keys:
12+
# https://docs.akash.network/intro-to-akash/stack-definition-language#services
213
services:
3-
tetris:
4-
image: bsord/tetris
14+
# The name of the service "web"
15+
web:
16+
# The docker container image with version. You must specify a version, the "latest" tag doesn't work.
17+
image: akashlytics/hello-akash-world:0.2.0
18+
# You can map ports here https://docs.akash.network/intro-to-akash/stack-definition-language#services.expose
519
expose:
6-
- port: 80
20+
- port: 3000
721
as: 80
822
to:
923
- global: true
24+
25+
# The profiles section contains named compute and placement profiles to be used in the deployment.
26+
# https://docs.akash.network/intro-to-akash/stack-definition-language#profiles
1027
profiles:
28+
# profiles.compute is map of named compute profiles. Each profile specifies compute resources to be leased for each service instance uses uses the profile.
29+
# https://docs.akash.network/intro-to-akash/stack-definition-language#profiles.compute
1130
compute:
12-
tetris:
31+
# The name of the service
32+
web:
1333
resources:
1434
cpu:
15-
units: 1
35+
units: 0.5
1636
memory:
1737
size: 512Mi
1838
storage:
19-
- size: 512Mi
20-
gpu:
21-
units: 0
39+
size: 512Mi
40+
41+
# profiles.placement is map of named datacenter profiles. Each profile specifies required datacenter attributes and pricing configuration for each compute profile that will be used within the datacenter. It also specifies optional list of signatures of which tenants expects audit of datacenter attributes.
42+
# https://docs.akash.network/intro-to-akash/stack-definition-language#profiles.placement
2243
placement:
23-
akash:
24-
attributes:
25-
host: akash
26-
signedBy:
27-
anyOf:
28-
- akash1365yvmc4s7awdyj3n2sav7xfx76adc6dnmlx63
29-
- akash18qa2a2ltfyvkyj0ggj3hkvuj6twzyumuaru9s4
44+
dcloud:
3045
pricing:
31-
tetris:
46+
# The name of the service
47+
web:
3248
denom: uakt
33-
amount: 10000
49+
amount: 1000
50+
51+
# The deployment section defines how to deploy the services. It is a mapping of service name to deployment configuration.
52+
# https://docs.akash.network/intro-to-akash/stack-definition-language#deployment
3453
deployment:
35-
tetris:
36-
akash:
37-
profile: tetris
38-
count: 1
54+
# The name of the service
55+
web:
56+
dcloud:
57+
profile: web
58+
count: 1

‎examples/get_deployments.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QueryDeploymentsResponse, QueryDeploymentsRequest, QueryClientImpl } from "@akashnetwork/akashjs/build/protobuf/akash/deployment/v1beta3/query";
1+
import { QueryDeploymentsResponse, QueryDeploymentsRequest, QueryClientImpl } from "@akashnetwork/akash-api/akash/deployment/v1beta3";
22
import { getRpc } from "@akashnetwork/akashjs/build/rpc";
33

44
async function main() {

‎examples/get_lease_status.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QueryClientImpl, QueryLeaseRequest, QueryLeaseResponse } from "@akashnetwork/akashjs/build/protobuf/akash/market/v1beta3/query";
1+
import { QueryClientImpl, QueryLeaseRequest, QueryLeaseResponse } from "@akashnetwork/akash-api/akash/market/v1beta3";
22
import { getRpc } from "@akashnetwork/akashjs/build/rpc";
33

44
async function main() {

‎examples/list_all_providers.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QueryClientImpl, QueryProvidersRequest, QueryProvidersResponse } from "@akashnetwork/akashjs/build/protobuf/akash/provider/v1beta3/query";
1+
import { QueryClientImpl, QueryProvidersRequest, QueryProvidersResponse } from "@akashnetwork/akash-api/akash/provider/v1beta3";
22
import { getRpc } from "@akashnetwork/akashjs/build/rpc";
33

44
async function main() {

‎examples/take_down_deployment.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing";
22
import { SigningStargateClient } from "@cosmjs/stargate";
3-
4-
// import the required message type from akashjs
5-
import { getAkashTypeRegistry, getTypeUrl } from "@akashnetwork/akashjs/build/stargate/index";
6-
import { MsgCloseDeployment } from "@akashnetwork/akashjs/build/protobuf/akash/deployment/v1beta3/deploymentmsg";
3+
import { getAkashTypeRegistry, getTypeUrl } from "@akashnetwork/akashjs/build/stargate";
4+
import { MsgCloseDeployment } from "@akashnetwork/akash-api/akash/deployment/v1beta3";
75

86
async function main() {
97
const mnemonic = "your wallet mnemonic";

0 commit comments

Comments
 (0)