Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ensdomains/ccip-read-router

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ensdomains/ccip-read-router

A lightweight package for routing CCIP-Read requests, using [itty-router](https://itty.dev/itty-router/).

  • 0.0.6
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@ensdomains/ccip-read-router

A lightweight package for routing CCIP-Read requests, using itty-router.

Getting started

Install with:

bun add @ensdomains/ccip-read-router itty-router viem

Basic usage

import { CcipReadRouter } from "@ensdomains/ccip-read-router";

// 1. Create a router instance
const router = CcipReadRouter();

// 2. Add a route
router.add({
  // Function signature for the route
  type: "function bar(uint256) pure returns (uint256)",
  // Handler, with args based on function signature
  handle: async ([x]) => {
    // Return type based on function signature, or arbitrary hex (0x...)
    return [x * 2n];
  },
});

// 3. Consume the router...

Customisation

Most customisation is inherited from itty-router.

Base URL
import { CcipReadRouter } from "@ensdomains/ccip-read-router";

const router = CcipReadRouter({ base: "/ccip-read" });
CORS

From itty-router docs:

import { CcipReadRouter } from "@ensdomains/ccip-read-router";
import { cors } from "itty-router";

// get preflight and corsify pair
const { preflight, corsify } = cors();

const router = CcipReadRouter({
  before: [preflight], // add preflight upstream
  finally: [corsify], // and corsify downstream
});

Runtimes

Cloudflare Workers

Just export the router from your worker file.

import { CcipReadRouter } from "@ensdomains/ccip-read-router";

const router = CcipReadRouter();

router.add({
  type: "function bar(uint256) pure returns (uint256)",
  handle: async ([x]) => {
    return [x * 2n];
  },
});

export default { ...router };
Bun

Initialise the router with the port you want to use, and export.

import { CcipReadRouter } from "@ensdomains/ccip-read-router";

const router = CcipReadRouter({ port: 3001 });

router.add({
  type: "function bar(uint256) pure returns (uint256)",
  handle: async ([x]) => {
    return [x * 2n];
  },
});

export default router;
Node usage

Use the @whatwg-node/server adapter.

import { CcipReadRouter } from "@ensdomains/ccip-read-router";
import { createServerAdapter } from "@whatwg-node/server";
import { createServer } from "http";

const router = CcipReadRouter();

router.add({
  type: "function bar(uint256) pure returns (uint256)",
  handle: async ([x]) => {
    return [x * 2n];
  },
});

// create a @whatwg-node/server
const ccipReadServer = createServerAdapter(router.fetch);

// then pass that to Node
const httpServer = createServer(ccipReadServer);
httpServer.listen(3001);

Other runtimes

See the runtime guides section of the itty-router docs.

FAQs

Package last updated on 10 Sep 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc