dogecoin-core-trpc-api 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2025 Simon Betton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,241 @@
1
+ # 🐕 Dogecoin Core tRPC API
2
+
3
+ ## 🌟 Project Description
4
+
5
+ The `dogecoin-core-trpc-api` project is a Node.js-based API designed to interact with Dogecoin Core. It uses modern TypeScript tooling and libraries like `trpc` for building APIs, `zod` for validation, and `ky` for HTTP requests. The project is modular and follows best practices for scalability and maintainability.
6
+
7
+ This API is designed to be private and limited in scope, providing a secure interface to the Dogecoin Core RPC API. It is intended to be accessed exclusively via a Cloudflare Tunnel and paired with a Cloudflare Workers project for seamless and secure access.
8
+
9
+ ## 🛠️ Tech Stack
10
+
11
+ - **Node.js**: JavaScript runtime.
12
+ - **TypeScript**: Better tooling and type safety for JavaScript applications.
13
+ - **tRPC**: End-to-end type-safe APIs made easy.
14
+ - **Zod**: Schema declaration and validation library.
15
+ - **Ky**: A tiny and elegant HTTP client for making requests.
16
+ - **Cloudflare Tunnel**: Securely exposes the API to the Cloudflare network.
17
+
18
+ ---
19
+
20
+ ## 🛠️ Setup Commands
21
+
22
+ ### 🔧 Development Mode
23
+
24
+ - **Command**: `npm run dev`
25
+ - **Description**: Starts the development server with live reloading using `tsx` and environment variables managed by `dotenvx`.
26
+
27
+ ### 🏗️ Build
28
+
29
+ - **Command**: `npm run build`
30
+ - **Description**: Compiles the TypeScript code into a production-ready format using `tsup`.
31
+
32
+ ---
33
+
34
+ ## 📦 Installable Typesafe Client
35
+
36
+ You can install the client in a separate environment and make typesafe requests
37
+ against the deployed Dogecoin Core tRPC API.
38
+
39
+ ```bash
40
+ npm install dogecoin-core-trpc-api
41
+ ```
42
+
43
+ ```ts
44
+ import { createDogecoinCoreClient } from "dogecoin-core-trpc-api/client";
45
+
46
+ const client = createDogecoinCoreClient();
47
+
48
+ const health = await client.health.query();
49
+ console.log(health);
50
+ ```
51
+
52
+ By default, the client targets `https://rpc.dogeapi.io`.
53
+
54
+ To point at a custom deployment, provide a URL that matches your tRPC endpoint:
55
+
56
+ ```ts
57
+ const client = createDogecoinCoreClient({
58
+ url: "https://<your-tunnel-domain>/trpc",
59
+ });
60
+ ```
61
+
62
+ ---
63
+
64
+ ## Library Usage
65
+
66
+ You can embed the server in another Node.js app by importing the router:
67
+
68
+ ```ts
69
+ import { createHTTPServer } from "@trpc/server/adapters/standalone";
70
+ import { appRouter } from "dogecoin-core-trpc-api/server";
71
+
72
+ const server = createHTTPServer({ router: appRouter });
73
+ server.listen(3000);
74
+ ```
75
+
76
+ ### 🚀 Start
77
+
78
+ - **Command**: `npm run start`
79
+ - **Description**: Runs the compiled application in production mode.
80
+
81
+ ### 📦 Publish
82
+
83
+ - Deploy any way you like, for example using `rsync`:
84
+
85
+ ```bash
86
+ rsync -avz <location-to-project>/dist/ root@<droplet-ip>:~/dogecoin-core-api/
87
+ pm2 restart API
88
+ ```
89
+
90
+ - **Description**: Deploys the built application to a remote server using `rsync`.
91
+
92
+ ---
93
+
94
+ ## 🌐 Digital Ocean Server Setup
95
+
96
+ Follow these steps to set up a Digital Ocean server (Ubuntu 25.04, Basic Premium Intel NVMe SSD, 4GB, 2 CPUs) with a 250GB Block Storage volume attached:
97
+
98
+ ### ⚙️ Initial Setup
99
+
100
+ ```bash
101
+ sudo apt update && sudo apt upgrade -y
102
+ reboot
103
+ sudo apt install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils git
104
+ wget https://github.com/dogecoin/dogecoin/releases/download/v1.14.9/dogecoin-1.14.9-x86_64-linux-gnu.tar.gz
105
+ tar -xvzf dogecoin-1.14.9-x86_64-linux-gnu.tar.gz
106
+ mv dogecoin-1.14.9/bin/* /usr/local/bin/
107
+ mkdir -p ~/.dogecoin
108
+ touch ~/.dogecoin/dogecoin.conf
109
+ nano ~/.dogecoin/dogecoin.conf
110
+ ```
111
+
112
+ ### 📝 Dogecoin Configuration File
113
+
114
+ ```ini
115
+ server=1
116
+ rpcuser=<your_rpc_username>
117
+ rpcpassword=<your_rpc_password>
118
+ rpcallowip=127.0.0.1
119
+
120
+ # Settings
121
+ maxconnections=125
122
+ datadir=/mnt/<your_volume_name>/dogecoin_data
123
+ blocksonly=0
124
+ maxuploadtarget=5G
125
+ txindex=1
126
+ ```
127
+
128
+ ### 🚀 Start Dogecoin Daemon
129
+
130
+ ```bash
131
+ mkdir /mnt/volume_sfo3_01/dogecoin_data
132
+ dogecoind -daemon
133
+ ```
134
+
135
+ ### 📦 Install Node.js and PM2
136
+
137
+ ```bash
138
+ sudo apt install nodejs npm -y
139
+ sudo npm install -g pm2
140
+ mkdir ~/dogecoin-core-api
141
+ ```
142
+
143
+ ### 🏗️ Build the Project and Deploy
144
+
145
+ Refer to the `build` and `publish` sections above for the necessary commands to build and deploy the project.
146
+
147
+ ### 🌐 Set API Environment Variables
148
+
149
+ Set the following environment variables to configure the API:
150
+
151
+ ```bash
152
+ export RPC_USER=<your_rpc_username>
153
+ export RPC_PASSWORD=<your_rpc_password>
154
+ export RPC_HOST=<your_dogecoin_node_ip>
155
+ ```
156
+
157
+ ### 🚀 Start the API
158
+
159
+ Use PM2 to start and manage the API process efficiently:
160
+
161
+ ```bash
162
+ pm2 start ~/dogecoin-core-api/index.cjs --name "API"
163
+ ```
164
+
165
+ ### ☁️ Cloudflare Tunnel Setup
166
+
167
+ ```bash
168
+ wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
169
+ sudo dpkg -i cloudflared-linux-amd64.deb
170
+ cloudflared tunnel login
171
+ cloudflared tunnel create dogecoin-core-node-internal-api
172
+ nano ~/.cloudflared/config.yml
173
+ ```
174
+
175
+ ### 🛠️ Cloudflare Tunnel Configuration
176
+
177
+ Configure `~/.cloudflared/config.yml`:
178
+
179
+ ```yaml
180
+ tunnel: dogecoin-core-node-internal-api
181
+ credentials-file: /root/.cloudflared/<tunnel-id>.json
182
+
183
+ ingress:
184
+ - hostname: <your-domain.com>
185
+ service: http://localhost:3000
186
+ - service: http_status:404
187
+ ```
188
+
189
+ ### ✅ Confirm the Tunnel Works
190
+
191
+ ```bash
192
+ cloudflared tunnel run dogecoin-core-node-internal-api
193
+ ```
194
+
195
+ ### 🔄 Systemd Service Configuration
196
+
197
+ ```bash
198
+ sudo nano /etc/systemd/system/cloudflared-doge.service
199
+ ```
200
+
201
+ ```ini
202
+ [Unit]
203
+ Description=Cloudflare Tunnel for Dogecoin Core Node
204
+ After=network.target
205
+
206
+ [Service]
207
+ ExecStart=/usr/local/bin/cloudflared tunnel --no-autoupdate run dogecoin-core-node-internal-api
208
+ Restart=always
209
+ User=root
210
+ Environment=HOME=/root
211
+
212
+ [Install]
213
+ WantedBy=multi-user.target
214
+ ```
215
+
216
+ ### 🔧 Enable and Start the Cloudflare Tunnel Service
217
+
218
+ ```bash
219
+ sudo systemctl daemon-reload
220
+ sudo systemctl enable cloudflared-doge
221
+ sudo systemctl start cloudflared-doge
222
+ ```
223
+
224
+ ## 🔖 Releasing
225
+
226
+ This project uses `standard-version` to generate changelogs and bump semantic versions.
227
+
228
+ Local release steps:
229
+
230
+ ```bash
231
+ # install dev dependency
232
+ npm install --save-dev standard-version
233
+
234
+ # create a release based on Conventional Commits (or use --release-as)
235
+ npm run release
236
+
237
+ # push created tag and release commit (if not using CI)
238
+ git push --follow-tags origin main
239
+ ```
240
+
241
+ If you prefer automated releases in CI, the repository includes a GitHub Actions workflow that runs `npm run release` on pushes to `main`. Ensure commits follow Conventional Commits (feat:, fix:, chore:, BREAKING CHANGE) to get automatic semantic versioning. If you don't follow that convention, you can control the bump with `--release-as <patch|minor|major>`.