Skip to content

Commit 7eb8dc7

Browse files
feat: added deno docs (#30)
* feat: added deno docs * chore: deno docs cleanup * chore: cleanup v2
1 parent 3ed0d0e commit 7eb8dc7

File tree

5 files changed

+191
-0
lines changed

5 files changed

+191
-0
lines changed

pages/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"python": "Python",
3434
"go": "Go",
3535
"nodejs": "NodeJS",
36+
"deno": "Deno",
3637
"dotnet": ".NET",
3738
"-- Ecosystem --": {
3839
"type": "separator",

pages/deno.mdx

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Deno with Node.js SDK
2+
3+
The UTxORPC SDK, an npm package for interacting with UTxORPC-compatible nodes, is also compatible with Deno thanks to the latest 'Deno 2' update. This allows you to fetch blocks, submit transactions, and synchronize with the latest blocks seamlessly using Deno's now native npm package support.
4+
5+
## Prerequisites
6+
7+
Ensure you have Deno 2.0 or higher installed. Deno 2 is compatible with Node.js and npm packages, which allows you to use the `@utxorpc/sdk` package directly in your Deno project.
8+
9+
To install Deno, refer to the [official Deno installation guide](https://deno.land/[email protected]/getting_started/installation).
10+
11+
## Project Setup
12+
13+
You can set up a new Deno project with the `deno init` command, which generates a `deno.json` configuration file to manage dependencies and settings.
14+
15+
```bash
16+
deno init
17+
```
18+
19+
After running this command, you’ll see a `deno.json` file in your project directory.
20+
21+
## Installation with `deno add`
22+
23+
With Deno 2, you can use `deno add` to install npm packages without needing a `package.json` or `node_modules` folder. To install the UTxORPC SDK, run:
24+
25+
```bash
26+
deno add npm:@utxorpc/sdk
27+
```
28+
29+
Running this command will add `@utxorpc/sdk` to your project and update `deno.json` with an entry for `@utxorpc/sdk` as a dependency.
30+
31+
## Manual Installation
32+
33+
In Deno 2, you can also use npm packages without a `package.json` or `node_modules` folder as long as you used `deno init` . Instead, you can directly specify the package using the `npm:` prefix and it will automatically do everything for you even without the import in your `deno.json`.
34+
35+
```typescript
36+
import { CardanoSyncClient, CardanoQueryClient, CardanoSubmitClient } from "npm:@utxorpc/sdk";
37+
```
38+
39+
If you'd prefer to use a configuration file to manage dependencies, add an `npm:` specifier in your `deno.json` configuration if you manually added it without using `deno add` and even when using this command it should also look like this:
40+
41+
```json
42+
// deno.json
43+
{
44+
"imports": {
45+
"@utxorpc/sdk": "npm:@utxorpc/sdk"
46+
}
47+
}
48+
```
49+
50+
Then import as follows:
51+
52+
```typescript
53+
import { CardanoSyncClient, CardanoQueryClient, CardanoSubmitClient } from "@utxorpc/sdk";
54+
```
55+
56+
## Overview
57+
58+
The SDK includes three primary clients for interacting with UTxORPC nodes:
59+
60+
1. **CardanoSyncClient**: Synchronize chain data, fetch blocks, and track blockchain tips.
61+
2. **CardanoQueryClient**: Submit transactions and monitor their progress.
62+
3. **CardanoSubmitClient**: Query the ledger state and construct new transactions.
63+
64+
## Usage
65+
66+
The following code samples assume that the UTxORPC node is running locally on `localhost:50051`. If your node is hosted remotely or on a different server, replace `"http://localhost:50051"` with the appropriate server URL and port for your environment.
67+
68+
For more details on configuring your node, refer to the [UTxORPC Ecosystem Servers Documentation](/servers).
69+
70+
Below are examples of how to use each of the clients in the SDK.
71+
72+
### 1. CardanoSyncClient
73+
74+
`CardanoSyncClient` helps you follow the tip and fetch specific blocks.
75+
76+
#### Example: Following the Tip
77+
78+
```typescript
79+
import { CardanoSyncClient } from "npm:@utxorpc/sdk";
80+
81+
async function followTipExample() {
82+
const syncClient = new CardanoSyncClient({
83+
uri: "http://localhost:50051"
84+
});
85+
86+
const tip = syncClient.followTip([
87+
{ slot: 54131816, hash: "34c65aba4b299113a488b74e2efe3a3dd272d25b470d25f374b2c693d4386535" },
88+
]);
89+
90+
for await (const event of tip) {
91+
console.log(event);
92+
}
93+
}
94+
95+
followTipExample().catch(console.error);
96+
```
97+
98+
#### Example: Fetching a Block
99+
100+
```typescript
101+
import { CardanoSyncClient } from "npm:@utxorpc/sdk";
102+
103+
async function fetchBlockExample() {
104+
const syncClient = new CardanoSyncClient({
105+
uri: "http://localhost:50051"
106+
});
107+
108+
const block = await syncClient.fetchBlock({
109+
slot: 54131816,
110+
hash: "34c65aba4b299113a488b74e2efe3a3dd272d25b470d25f374b2c693d4386535",
111+
});
112+
113+
console.log(block);
114+
}
115+
116+
fetchBlockExample().catch(console.error);
117+
```
118+
119+
### 2. CardanoQueryClient
120+
121+
`CardanoQueryClient` lets you query blockchain data, read protocol parameters, and search UTXOs.
122+
123+
#### Example: Reading Blockchain Parameters
124+
125+
```typescript
126+
import { CardanoQueryClient } from "npm:@utxorpc/sdk";
127+
128+
async function readParamsExample() {
129+
const queryClient = new CardanoQueryClient({
130+
uri: "http://localhost:50051"
131+
});
132+
133+
const params = await queryClient.readParams();
134+
console.log(params);
135+
}
136+
137+
readParamsExample().catch(console.error);
138+
```
139+
140+
#### Example: Searching UTXOs by Address
141+
142+
```typescript
143+
import { CardanoQueryClient } from "npm:@utxorpc/sdk";
144+
145+
async function searchUtxosByAddressExample() {
146+
const queryClient = new CardanoQueryClient({
147+
uri: "http://localhost:50051"
148+
});
149+
150+
const utxos = await queryClient.searchUtxosByAddress(
151+
Buffer.from("705c87cbca3a88cbfee6f6ad820acea99f484b4830fc632610f2a30146", "hex")
152+
);
153+
154+
utxos.forEach((utxo) => {
155+
console.log(utxo);
156+
});
157+
}
158+
159+
searchUtxosByAddressExample().catch(console.error);
160+
```
161+
162+
### 3. CardanoSubmitClient
163+
164+
`CardanoSubmitClient` allows transaction submission.
165+
166+
#### Example: Submitting a Transaction
167+
168+
```typescript
169+
import { CardanoSubmitClient } from "npm:@utxorpc/sdk";
170+
171+
async function submitTxExample() {
172+
const submitClient = new CardanoSubmitClient({
173+
uri: "http://localhost:50051"
174+
});
175+
176+
const txSample = "84a300d90102818258203dc5d9977e7b3d51acaea81031d2f461404536b2828549b73876a5980295f81b00018282581d60916c769efc6e2a3339594818a1d0c3998c29e3a6303d8711de8567591a004c4b4082581d60916c769efc6e2a3339594818a1d0c3998c29e3a6303d8711de8567591b0000000253bcffb3021a0002990da100d9010281825820526fa19e3694cda4f3c0d2fb2d2bb8768925eccc49a89d5f12b1972644ac769858403d6d6599193b17e67827cd9f48aaf35ac762c6fb0c5402c52724f307b69ff96f3f7e6c3fb107670c28679c148bf510f479c01a34b9d95d0dbb7e4ff6f3cb560af5f6";
177+
const txHash = await submitClient.submitTx(Buffer.from(txSample, "hex"));
178+
179+
const txHashHex = Buffer.from(txHash).toString("hex");
180+
console.log(txHashHex);
181+
}
182+
183+
submitTxExample().catch(console.error);
184+
```
185+
186+
## Conclusion
187+
188+
The NodeJS UTxORPC SDK which is compatible with the Deno runtime allows seamless integration with UTxORPC nodes. With Deno’s compatibility with npm, you can access `@utxorpc/sdk` easily and use its tools for building robust blockchain applications in a secure and modern environment while utilizing Deno's wide variety of tools.

pages/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ import { CardGrid, Card, SDKCard, SectionHeader } from "../components/features";
6464
<SDKCard title="Rust SDK" iconSrc="rust.png" href="rust" />
6565
<SDKCard title="NodeJS SDK" iconSrc="node.png" href="nodejs" />
6666
<SDKCard title=".NET SDK" iconSrc="dotnet.png" href="dotnet" />
67+
<SDKCard title="Deno SDK" iconSrc="deno.png" href="deno" />
6768
</CardGrid>

pages/introduction.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Thanks to all of the available gRPC toolchain, generating SDKs in several progra
4343
<Card title="NodeJs" href="nodejs" />
4444
<Card title="Python" href="python" />
4545
<Card title=".NET" href="dotnet" />
46+
<Card title="Deno" href="deno" />
4647

4748

4849
</Cards>

public/deno.png

86.5 KB
Loading

0 commit comments

Comments
 (0)