1+ import { kavaToUkava , Kiln } 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_prod.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 : 37
19+ } ;
20+
21+ try {
22+ console . log ( 'crafting...' ) ;
23+ const tx = await k . client . POST (
24+ '/v1/kava/transaction/stake' ,
25+ {
26+ body : {
27+ account_id : process . env . KILN_ACCOUNT_ID as string ,
28+ pubkey : '0233335b6c68a85e01b85055d0e8c2fcef42fed977898422ef3a5f6baf9a9a413e' ,
29+ validator : 'kavavaloper1djqecw6nn5tydxq0shan7srv8j65clsf79myt8' ,
30+ amount_ukava : kavaToUkava ( '0.01' ) . toString ( ) ,
31+ }
32+ }
33+ ) ;
34+ console . log ( 'signing...' ) ;
35+ if ( ! tx . data ?. data ) throw new Error ( 'No data in response' ) ;
36+ const signResponse = await k . fireblocks . signKavaTx ( vault , tx . data . data ) ;
37+ console . log ( 'broadcasting...' ) ;
38+ if ( ! signResponse . signed_tx ?. data ?. signed_tx_serialized ) throw new Error ( 'No signed_tx in response' ) ;
39+ const broadcastedTx = await k . client . POST ( "/v1/kava/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