Skip to content

Commit 0fa9f46

Browse files
authored
add sol example to sdk (#131)
* add sol example to sdk * nit
1 parent 7fbbf57 commit 0fa9f46

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

examples/sol.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Kiln, solToLamports } from "../src/kiln";
2+
import fs from "node:fs";
3+
import 'dotenv/config'
4+
import type { FireblocksIntegration } from "../src/fireblocks.ts";
5+
6+
7+
const apiSecret = fs.readFileSync(`${__dirname}/fireblocks_secret.key`, 'utf8');
8+
9+
const k = new Kiln({
10+
baseUrl: process.env.KILN_API_URL as string,
11+
apiToken: process.env.KILN_API_KEY as string,
12+
});
13+
14+
const vault: FireblocksIntegration = {
15+
provider: 'fireblocks',
16+
fireblocksApiKey: process.env.FIREBLOCKS_API_KEY as string,
17+
fireblocksSecretKey: apiSecret,
18+
vaultId: 14
19+
};
20+
21+
try {
22+
console.log('crafting...');
23+
const tx = await k.client.POST(
24+
'/v1/sol/transaction/stake',
25+
{
26+
body: {
27+
account_id: 'd3f1b917-72b1-4982-a4dd-93fce579a708',
28+
wallet: 'E9qDxpwuPFeFB7vDdDibdCbWwHy867eYz3rV29bAevuC',
29+
amount_lamports: solToLamports('0.01').toString(),
30+
vote_account_address: 'FwR3PbjS5iyqzLiLugrBqKSa5EKZ4vK9SKs7eQXtT59f'
31+
}
32+
}
33+
);
34+
console.log('signing...');
35+
if(!tx.data) throw new Error('No data in response');
36+
const signResponse = await k.fireblocks.signSolTx(vault, tx.data.data, "SOL_TEST");
37+
if(!signResponse.signed_tx?.data.signed_tx_serialized) throw new Error('No signed_tx in response');
38+
console.log('broadcasting...');
39+
const broadcastedTx = await k.client.POST("/v1/sol/transaction/broadcast", {
40+
body: {
41+
tx_serialized: signResponse.signed_tx.data.signed_tx_serialized
42+
}
43+
});
44+
console.log(broadcastedTx);
45+
46+
} catch (err) {
47+
console.log(err);
48+
}

src/fireblocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Client } from 'openapi-fetch';
33
import { FireblocksSigner } from './fireblocks_signer';
44
import type { components, paths } from './openapi/schema';
55

6-
type FireblocksIntegration = {
6+
export type FireblocksIntegration = {
77
provider: 'fireblocks';
88
fireblocksApiKey: string;
99
fireblocksSecretKey: string;

0 commit comments

Comments
 (0)