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+ }
0 commit comments