Skip to content

Instantly share code, notes, and snippets.

@cvonkleist
Created June 14, 2024 08:07
Show Gist options
  • Save cvonkleist/98efbfdd4a815673295f22153edf57ea to your computer and use it in GitHub Desktop.
Save cvonkleist/98efbfdd4a815673295f22153edf57ea to your computer and use it in GitHub Desktop.
There are too many old references to how to use Ruby's Net::HTTP to do SSL, post JSON, etc., so here is a simple, fairly modern example for future reference, posting a JSON-RPC call.
require "json"
require "net/http"
url = "https://mainnet.era.zksync.io"
pp JSON.parse(Net::HTTP.post(URI.parse(url), {"method": "eth_blockNumber", "params": [], "id":1, "jsonrpc":"2.0"}.to_json, "Content-Type" => "application/json").body)
# => {"jsonrpc"=>"2.0", "result"=>"0x22d9d5d", "id"=>1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment