diff --git a/.gitignore b/.gitignore index 2a39824..615f1f2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ # Ignore node modules **/node_modules +**/deno.lock package-lock.json bun.lockb *.js diff --git a/examples/deno/deno.json b/examples/deno/deno.json new file mode 100644 index 0000000..b1a7c0d --- /dev/null +++ b/examples/deno/deno.json @@ -0,0 +1,6 @@ +{ + "tasks": { + "start": "deno run dump-history.ts" + }, + "imports": { "@utxorpc/sdk": "npm:@utxorpc/sdk@^0.6.3" } +} diff --git a/examples/deno/dump-history.ts b/examples/deno/dump-history.ts new file mode 100644 index 0000000..3743dd3 --- /dev/null +++ b/examples/deno/dump-history.ts @@ -0,0 +1,31 @@ +import { CardanoSyncClient } from "npm:@utxorpc/sdk"; +import { Buffer } from "node:buffer"; + +let client = new CardanoSyncClient({ + uri: "http://localhost:50051", +}); + +let next_token: any = { + hash: new Uint8Array( + Buffer.from( + "125ff4eb8168a03e34ed003975ed95b8844b1e751274fd5ce1b5abd8ca5b9908", + "hex" + ) + ), + index: BigInt(55194964), +}; + +async function crawlAll() { + while (!!next_token) { + console.log("start"); + let chunk = await client.inner.dumpHistory({ + startToken: next_token, + maxItems: 10, + }); + + console.log(chunk.nextToken?.index); + next_token = chunk.nextToken; + } +} + +crawlAll().then(console.log); diff --git a/examples/deno/follow-tip.ts b/examples/deno/follow-tip.ts new file mode 100644 index 0000000..cb87e89 --- /dev/null +++ b/examples/deno/follow-tip.ts @@ -0,0 +1,40 @@ +import { Buffer } from "node:buffer"; +import { CardanoSyncClient, CardanoQueryClient } from "npm:@utxorpc/sdk"; + +async function test() { + let syncClient = new CardanoSyncClient({ + uri: "http://localhost:50051", + }); + + let queryClient = new CardanoQueryClient({ + uri: "http://localhost:50051", + }); + + const params = await queryClient.readParams(); + + console.log(params); + + const utxos = await queryClient.searchUtxosByAddress( + Buffer.from( + "705c87cbca3a88cbfee6f6ad820acea99f484b4830fc632610f2a30146", + "hex" + ) + ); + console.log( + utxos.map((utxo) => { + console.log(utxo.parsedValued?.script); + }) + ); + + let tip = syncClient.followTip([ + { + slot: 62085439, + hash: "6783d7569edf4b861313714274d3ba99383371d40f4253273392b581239d5db6", + }, + ]); + + for await (const event of tip) { + console.log(event); + } +} +test().catch(console.error); diff --git a/examples/deno/submit-tx.ts b/examples/deno/submit-tx.ts new file mode 100644 index 0000000..a713c0c --- /dev/null +++ b/examples/deno/submit-tx.ts @@ -0,0 +1,29 @@ +import { Buffer } from "node:buffer"; +import { CardanoSubmitClient } from "npm:@utxorpc/sdk"; + +const TX1 = + "84a30081825820639b4af1e7bf25edd5d9dfb63ea79827a25e15b2ecf2bc861eeeeead0279108901018282583900e63022b0f461602484968bb10fd8f872787b862ace2d7e943292a37003ec6a12860ef8c07d4c1a8de7df06acb0f0330a6087ecbe972082a71a00766272825839004693c0ac525d045cb0a4e75bd3adbd6956b3b744e88d21e041fc9b630df092006419e469e0c77876a499124bf903735b434c7989f7a8090a1b000000025208a690021a00029075a10081825820e6e75c7876c610afd28a19c2947e72c1a629ab7903283e14915badee7c55402e5840b5d23d73a2c52515862310b08c94d51c6a0ccc2a6d61008d67070317a4dff6e0e41ae62423852007bfa6778162296362c0a1f951ad7634706a1ac6922085b602f5f6"; +const TX2 = + "84a30081825820639b4af1e7bf25edd5d9dfb63ea79827a25e15b2ecf2bc861eeeeead0279108901018282583900f97ccf4fe384174e63f2250a3c4a61f851112ed0b93caeb6aa84308e95d8feca512588e1a954ee5a8ae2beff32ea360590be694b5065d8581a00766272825839004693c0ac525d045cb0a4e75bd3adbd6956b3b744e88d21e041fc9b630df092006419e469e0c77876a499124bf903735b434c7989f7a8090a1b000000025208a690021a00029075a10081825820e6e75c7876c610afd28a19c2947e72c1a629ab7903283e14915badee7c55402e58409cbeb67bc43d81563790eeb7e7c80ab4af569ba062e6cb345fc0049107ca5127533eafab1de2470841ff6c06ad1d630ac0e1de011350635be7d9e5685d1fe803f5f6"; + +const TX3 = + "84a30081825820639b4af1e7bf25edd5d9dfb63ea79827a25e15b2ecf2bc861eeeeead02791089010182825839002216b241048f34b97f34147116743df73dd7b0f814f8aacc04c778073e0feebba2d821e249ca4021efc12c2102cc6712c0c2a515add749861a00766272825839004693c0ac525d045cb0a4e75bd3adbd6956b3b744e88d21e041fc9b630df092006419e469e0c77876a499124bf903735b434c7989f7a8090a1b000000025208a690021a00029075a10081825820e6e75c7876c610afd28a19c2947e72c1a629ab7903283e14915badee7c55402e584053c535c66e66da1480522b6a3a722701b8c59b517d2b08bb47306a21a40d274ee33195b8e9a57c0cd91e08154e2f438bcc5ab7257d3ab5833e8d8520459b7d0df5f6"; + +async function test() { + let submitClient = new CardanoSubmitClient({ + uri: "http://localhost:50051", + }); + + let TXs = [ + Buffer.from(TX1, "hex"), + Buffer.from(TX2, "hex"), + Buffer.from(TX3, "hex"), + ]; + + for (const tx of TXs) { + const res = await submitClient.submitTx(tx); + console.log(res); + } +} + +test().catch(console.error);