Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
isomorphic-rpc
Advanced tools
A Javascript Object That Maps All Methods to RPC Calls as Promises (Isomorphic)
Exposes a Javascript object that maps all methods to RPC calls using Promises
"
In general this should support any RPC application, but I made it to simplify my ethereum applications and I've only used/tested it on the same.
eth_getBlockByHash
, web3 has only getBlock
)string
("0x1234") while others come back as number
and for some odd reason block.difficulty
is returned as a string
of decimal digits (lol WAHT?)getProof
are not supported (in web3 or other libraries) until each piece of software in the chain publishes a feature update to support it.Using Ecmascript's new Proxy
functionality you can create an object such that when you call a missing method on it, it instead calls a "handler" function that has access to the method name called.
The library uses this to automatically create an RPC request from any method name given. So any brand new or experimental RPC method your client software supports will be exposed.
The module is 37 lines of code. There is only 1 dependency (which branches into 3 small packages). It's only there to enables the library to be isomorphic.
The use of this library should work identically in both Node and all desktop/mobile Browsers (except Internet Explorer because bill gates is busy curing malaria)
This should probably work on all Javascript RPC applications because of its agnosticism to the actual methods being called.
But I haven't tried that yet so let me know!
Seems to be a good pattern because refactoring my code to use isomorphic-rpc is making tons of lines disappear.
npm install iso-rpc
const Rpc = require('./iso-rpc')
let rpc = new Rpc('http://localhost:8545') //for local node (default)
// or "https://mainnet.infura.io" or even "https://web3.gastracker.io" etc...
rpc.web3_sha3("0x").then((hash)=>{ console.log(hash) }).catch((e)=>{console.log(e)})
or within an async
function:
let hash = await rpc.web3_sha3("0x")
The JSON-RPC Page is the most up to date list of supported Ethereum RPC calls.
Also the RPC 2.0 Specification could be useful in updating this package. If a PR will help it better supports the RPC spec, I'll merge it in.
FAQs
A Javascript Object That Maps All Methods to RPC Calls as Promises (Isomorphic)
The npm package isomorphic-rpc receives a total of 49 weekly downloads. As such, isomorphic-rpc popularity was classified as not popular.
We found that isomorphic-rpc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.