Skip to content

Instantly share code, notes, and snippets.

@hazae41
Last active November 2, 2024 14:25
Show Gist options
  • Select an option

  • Save hazae41/9a96cc723d8916abee9c0235e7daa842 to your computer and use it in GitHub Desktop.

Select an option

Save hazae41/9a96cc723d8916abee9c0235e7daa842 to your computer and use it in GitHub Desktop.
This tutorial explains how to create a transaction simulator node for Network on Fly.io

Buy a domain name

https://www.cloudflare.com/products/registrar/

Create a Fly.io account

https://fly.io

Top up some money on Fly.io

$25 is recommended for a few months of service

Install the Fly.io CLI

https://fly.io/docs/flyctl/install/

Create a Tenderly account

https://tenderly.co

Generate an Ethereum private key and get some gas on Gnosis

You can use a bridge or a faucet to get some xDAI

You can start with 0.01 xDAI ($0.1) and fill it later

https://faucet.gnosischain.com

You can ask me for some if you have trouble

Create a Microserver

git clone https://github.com/hazae41/microserver node0 && cd ./node0

Then create a fly.toml file (e.g. a 512MB node at Singapore)

app = "node0"
primary_region = "sin"

[build]

[[vm]]
  memory = "512mb"
  cpu_kind = "shared"
  cpus = 1

[[services]]
  protocol = "tcp"
  internal_port = 8080
  auto_stop_machines = "off"
  auto_start_machines = false

  [[services.ports]]
    port = 80
    handlers = ["http"]

  [[services.ports]]
    port = 443
    handlers = ["tls", "http"]

    [services.ports.http_options]
      [services.ports.http_options.response]
        [services.ports.http_options.response.headers]
          Access-Control-Allow-Headers = "*"
          Access-Control-Allow-Methods = "*"
          Access-Control-Allow-Origin = "*"

Then launch it with

fly launch

Then go to fly.io to link your domain name to your server

Setup a JSON-RPC proxy for Ethereum

(You can also setup a JSON-RPC proxy for any EVM chain supported by Tenderly)

Clone the JSON-RPC proxy module into a mainnet subfolder

git submodule add https://github.com/hazae41/network-json-rpc-guard.git ./mods/mainnet

Edit your main.ts to route requests to your proxy

const mainnet = await Mainnet.main("MAINNET_")

const onHttpRequest = async (request: Request) => {
  if (request.headers.get("host")?.startsWith("mainnet."))
    return await mainnet.onHttpRequest(request)

  const url = new URL(request.url)

  if (url.pathname === "/mainnet")
    return await mainnet.onHttpRequest(request)

  return new Response("Not Found", { status: 404 })
}

Create a .env.local file with wss://signal.node0.hazae41.me as the signal server

MAINNET_SIGNALER_URL_LIST=wss://signal.node0.hazae41.me
MAINNET_SIGNALED_WS_URL=wss://<MY_DOMAIN>/mainnet
MAINNET_SIGNALED_HTTP_URL=https://<MY_DOMAIN>/mainnet
MAINNET_SIGNALED_PROTOCOL_LIST=eth:1,tenderly:1
MAINNET_ENDPOINT_WS_URL=wss://mainnet.gateway.tenderly.co/<API_KEY>
MAINNET_ENDPOINT_HTTP_URL=https://mainnet.gateway.tenderly.co/<API_KEY>
MAINNET_PRIVATE_KEY_ZERO_HEX=<PRIVATE_KEY>

Replace <MY_DOMAIN> by your domain name (e.g. node0.hazae41.me), <API_KEY> by your Tenderly API key, and <PRIVATE_KEY> by your Ethereum private key (starting by 0x)

Then copy the whole file content and import it in Fly

fly secrets import

Paste the content into your terminal and use Ctrl+D to terminate

fly deploy

Your changes are now deployed to your server

Enjoy $NET tokens when someone uses your server

https://gnosisscan.io/token/0x0a4d5EFEa910Ea5E39be428A3d57B80BFAbA52f4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment