forked from StellarRouter/StellarRouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick-start.ts
More file actions
39 lines (34 loc) · 1.2 KB
/
Copy pathquick-start.ts
File metadata and controls
39 lines (34 loc) · 1.2 KB
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
29
30
31
32
33
34
35
36
37
38
39
import { Keypair } from "@stellar/stellar-sdk";
import { RouterClient } from "../src/index.js";
import { RouterSdkError } from "../src/errors.js";
/**
* Minimal end-to-end example for the stellar-router-sdk.
*
* Point the client at a real network and real contract ids to use it. As
* written it only proves that construction + error surfacing work offline:
* the RPC calls fail fast because there is no network connection here.
*/
async function main(): Promise<void> {
const client = new RouterClient({
network: "testnet",
coreContractId: "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4",
quoteContractId: "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBMO",
keypair: Keypair.random(),
});
console.log(`network: ${client.network.rpcUrl}`);
console.log(`core: ${client.core.invoker.contractId}`);
try {
const address = await client.resolve("oracle");
console.log(`oracle resolves to ${address}`);
} catch (error) {
if (error instanceof RouterSdkError) {
console.error(`resolve failed with code ${error.code}: ${error.message}`);
} else {
throw error;
}
}
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});