forked from Axionvera/axionvera-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwithdrawExample.ts
More file actions
28 lines (20 loc) · 1000 Bytes
/
withdrawExample.ts
File metadata and controls
28 lines (20 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { Keypair } from "@stellar/stellar-sdk";
import { LocalKeypairWalletConnector, StellarClient, VaultContract } from "../src";
async function main(): Promise<void> {
const contractId = process.env.AXIONVERA_VAULT_CONTRACT_ID;
const secretKey = process.env.STELLAR_SECRET_KEY;
if (!contractId) throw new Error("AXIONVERA_VAULT_CONTRACT_ID is required");
if (!secretKey) throw new Error("STELLAR_SECRET_KEY is required");
const network = (process.env.STELLAR_NETWORK as "testnet" | "mainnet" | undefined) ?? "testnet";
const rpcUrl = process.env.STELLAR_RPC_URL;
const client = new StellarClient({ network, rpcUrl });
const wallet = new LocalKeypairWalletConnector(Keypair.fromSecret(secretKey));
const vault = new VaultContract({ client, contractId, wallet });
const amount = BigInt(process.env.AXIONVERA_WITHDRAW_AMOUNT ?? "1000");
const res = await vault.withdraw({ amount });
console.log(res);
}
main().catch((e) => {
console.error(e);
process.exit(1);
});