diff --git a/examples/sol.ts b/examples/sol.ts new file mode 100644 index 0000000..0d0dc34 --- /dev/null +++ b/examples/sol.ts @@ -0,0 +1,48 @@ +import { Kiln, solToLamports } from "../src/kiln"; +import fs from "node:fs"; +import 'dotenv/config' +import type { FireblocksIntegration } from "../src/fireblocks.ts"; + + +const apiSecret = fs.readFileSync(`${__dirname}/fireblocks_secret.key`, 'utf8'); + +const k = new Kiln({ + baseUrl: process.env.KILN_API_URL as string, + apiToken: process.env.KILN_API_KEY as string, +}); + +const vault: FireblocksIntegration = { + provider: 'fireblocks', + fireblocksApiKey: process.env.FIREBLOCKS_API_KEY as string, + fireblocksSecretKey: apiSecret, + vaultId: 14 +}; + +try { + console.log('crafting...'); + const tx = await k.client.POST( + '/v1/sol/transaction/stake', + { + body: { + account_id: 'd3f1b917-72b1-4982-a4dd-93fce579a708', + wallet: 'E9qDxpwuPFeFB7vDdDibdCbWwHy867eYz3rV29bAevuC', + amount_lamports: solToLamports('0.01').toString(), + vote_account_address: 'FwR3PbjS5iyqzLiLugrBqKSa5EKZ4vK9SKs7eQXtT59f' + } + } + ); + console.log('signing...'); + if(!tx.data) throw new Error('No data in response'); + const signResponse = await k.fireblocks.signSolTx(vault, tx.data.data, "SOL_TEST"); + if(!signResponse.signed_tx?.data.signed_tx_serialized) throw new Error('No signed_tx in response'); + console.log('broadcasting...'); + const broadcastedTx = await k.client.POST("/v1/sol/transaction/broadcast", { + body: { + tx_serialized: signResponse.signed_tx.data.signed_tx_serialized + } + }); + console.log(broadcastedTx); + +} catch (err) { + console.log(err); +} \ No newline at end of file diff --git a/src/fireblocks.ts b/src/fireblocks.ts index 9d3ee15..38e930f 100644 --- a/src/fireblocks.ts +++ b/src/fireblocks.ts @@ -3,7 +3,7 @@ import type { Client } from 'openapi-fetch'; import { FireblocksSigner } from './fireblocks_signer'; import type { components, paths } from './openapi/schema'; -type FireblocksIntegration = { +export type FireblocksIntegration = { provider: 'fireblocks'; fireblocksApiKey: string; fireblocksSecretKey: string;