1+ import { 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.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/xtz/transaction/delegate' ,
25+ {
26+ body : {
27+ account_id : 'd3f1b917-72b1-4982-a4dd-93fce579a708' ,
28+ wallet : 'tz1WmYmabzcmguEiJzZyL4rKDhBdgfa1bLod' ,
29+ baker_address : 'tz1YgDUQV2eXm8pUWNz3S5aWP86iFzNp4jnD'
30+ }
31+ }
32+ ) ;
33+ console . log ( 'signing...' ) ;
34+ if ( ! tx . data ) throw new Error ( 'No data in response' ) ;
35+ const signResponse = await k . fireblocks . signXtzTx ( vault , tx . data . data , "XTZ_TEST" ) ;
36+ if ( ! signResponse . signed_tx ?. data . signed_tx_serialized ) throw new Error ( 'No signed_tx in response' ) ;
37+ console . log ( 'broadcasting...' ) ;
38+ const broadcastedTx = await k . client . POST ( "/v1/xtz/transaction/broadcast" , {
39+ body : {
40+ tx_serialized : signResponse . signed_tx . data . signed_tx_serialized
41+ }
42+ } ) ;
43+ console . log ( broadcastedTx ) ;
44+
45+ } catch ( err ) {
46+ console . log ( err ) ;
47+ }
0 commit comments