From 3bceb39c8b8723d6b66d69bfde4890c90011aa57 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 22 Jan 2024 12:02:14 -0800 Subject: [PATCH 1/2] Update workers README and version --- README.md | 49 +++++++++++++++++++++++++++++++--------- worker/.dev.vars.example | 2 +- worker/package.json | 2 +- worker/wrangler.toml | 3 ++- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f3c7cb3..12dff9a 100644 --- a/README.md +++ b/README.md @@ -47,25 +47,52 @@ services: - 6379:6379 ``` -### 🦀 Cloudflare Worker +### 🦀 Cloudflare Workers + +#### Running locally: + +- + ```sh + cd worker + ``` +- Copy `.dev.vars.example` to [`.dev.vars`](https://developers.cloudflare.com/workers/configuration/environment-variables/#interact-with-environment-variables-locally) and fill in the values: + + ```sh + # .dev.vars is Cloudflare Wrangler's .env equivalent + cp .dev.vars.example .dev.vars + ``` +- Run the worker locally: + ```sh + pnpm dev + ``` +#### Deploying: + +- Create a [**KV namespace**](https://developers.cloudflare.com/kv/get-started/#3-create-a-kv-namespace) via `Wrangler`: + ```sh + pnpm wrangler kv:namespace create + ``` +- From the output, copy the `id` and replace the one in [`wrangler.toml`](./worker/wrangler.toml) line 8 with it. The `binding` value should remain as `enstate-1` regardless of what you named yours when you created it, + +- Deploy the worker: + + ```sh + pnpm wrangler deploy + ``` +- Upload your secrets: + ```sh + echo "https://rpc.ankr.com/eth/XXXXXX" | pnpm wrangler secret put RPC_URL + echo "XXXXX" | pnpm wrangler secret put OPENSEA_API_KEY + ``` -Running the cloudflare worker is as easy as running the following command: Additionally, there is a hosted instance available at [worker.enstate.rs](https://worker.enstate.rs). - -```sh -cd worker && pnpx wrangler deploy -``` - ## Contributing ### Standalone Server ```sh -cargo run -p enstate +cd server && cargo run -p enstate ``` ### Cloudflare Worker -```sh -cd worker && pnpm dev -``` +See [running Cloudflare Workers locally](#running-locally). diff --git a/worker/.dev.vars.example b/worker/.dev.vars.example index 6c08b01..1fe5c84 100644 --- a/worker/.dev.vars.example +++ b/worker/.dev.vars.example @@ -1,2 +1,2 @@ OPENSEA_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -UNIVERSAL_RESOLVER=0xc0497E381f536Be9ce14B0dD3817cBcAe57d2F62s + diff --git a/worker/package.json b/worker/package.json index c12cfe0..61231a1 100644 --- a/worker/package.json +++ b/worker/package.json @@ -8,6 +8,6 @@ "dev": "wrangler dev" }, "devDependencies": { - "wrangler": "^3.19.0" + "wrangler": "^3.23.0" } } diff --git a/worker/wrangler.toml b/worker/wrangler.toml index ae175e0..a545c5e 100644 --- a/worker/wrangler.toml +++ b/worker/wrangler.toml @@ -1,3 +1,4 @@ +#: schema https://github.com/cloudflare/workers-sdk/files/12887590/wrangler.schema.json name = "enstate-worker" main = "build/worker/shim.mjs" compatibility_date = "2023-03-22" @@ -14,4 +15,4 @@ kv_namespaces = [ command = "cargo install -q worker-build && worker-build --release" [vars] -OPENSEA_API_KEY="xxxx" +UNIVERSAL_RESOLVER="0xc0497E381f536Be9ce14B0dD3817cBcAe57d2F62" From 29be87f1e39025dfc6816585b4c48515e31b5c35 Mon Sep 17 00:00:00 2001 From: Luc Date: Wed, 24 Jan 2024 18:10:52 +0000 Subject: [PATCH 2/2] Update README.md --- README.md | 81 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 12dff9a..fe41882 100644 --- a/README.md +++ b/README.md @@ -49,42 +49,49 @@ services: ### 🦀 Cloudflare Workers -#### Running locally: - -- - ```sh - cd worker - ``` -- Copy `.dev.vars.example` to [`.dev.vars`](https://developers.cloudflare.com/workers/configuration/environment-variables/#interact-with-environment-variables-locally) and fill in the values: - - ```sh - # .dev.vars is Cloudflare Wrangler's .env equivalent - cp .dev.vars.example .dev.vars - ``` -- Run the worker locally: - ```sh - pnpm dev - ``` -#### Deploying: - -- Create a [**KV namespace**](https://developers.cloudflare.com/kv/get-started/#3-create-a-kv-namespace) via `Wrangler`: - ```sh - pnpm wrangler kv:namespace create - ``` -- From the output, copy the `id` and replace the one in [`wrangler.toml`](./worker/wrangler.toml) line 8 with it. The `binding` value should remain as `enstate-1` regardless of what you named yours when you created it, - -- Deploy the worker: - - ```sh - pnpm wrangler deploy - ``` -- Upload your secrets: - ```sh - echo "https://rpc.ankr.com/eth/XXXXXX" | pnpm wrangler secret put RPC_URL - echo "XXXXX" | pnpm wrangler secret put OPENSEA_API_KEY - ``` +```sh +cd worker +``` + +#### Run the worker locally + +```sh +cp .dev.vars.example .dev.vars +``` + +Edit your `.dev.vars` file at this time to include environment variables for `UNIVERSAL_RESOLVER`, `RPC_URL` (optional) and `OPENSEA_API_KEY` (optional). + +To run the worker locally you can now run: + +``` +pnpm dev +``` + +#### Deploying to Cloudflare Workers + +Create a [**KV namespace**](https://developers.cloudflare.com/kv/get-started/#3-create-a-kv-namespace) via `wrangler` or the Cloudflare dashboard. + +```sh +pnpm wrangler kv:namespace create +``` + +Copy the `id` of your newly created KV namespace to your [`wrangler.toml`](./worker/wrangler.toml). The `binding` value should remain as `enstate-1` regardless of what you named yours when you created it. + +Deploy the worker: + +```sh +pnpm wrangler deploy +``` + +Upload your secrets: + +```sh +echo "https://rpc.ankr.com/eth/XXXXXX" | pnpm wrangler secret put RPC_URL +echo "XXXXX" | pnpm wrangler secret put OPENSEA_API_KEY +``` Additionally, there is a hosted instance available at [worker.enstate.rs](https://worker.enstate.rs). + ## Contributing ### Standalone Server @@ -95,4 +102,8 @@ cd server && cargo run -p enstate ### Cloudflare Worker -See [running Cloudflare Workers locally](#running-locally). +```sh +cd worker && pnpm dev +``` + +For more information on running the worker locally, please see [running Cloudflare Workers locally](#run-the-worker-locally).