https://github.com/blockful/ccip-express
CCIP-Read Express router implementation
https://github.com/blockful/ccip-express
Last synced: 10 months ago
JSON representation
CCIP-Read Express router implementation
- Host: GitHub
- URL: https://github.com/blockful/ccip-express
- Owner: blockful
- Created: 2024-07-17T12:21:42.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-17T21:14:18.000Z (almost 2 years ago)
- Last Synced: 2025-07-11T15:54:14.963Z (12 months ago)
- Language: TypeScript
- Size: 31.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CCIP Express
Express CCIP-Read handler.
## Motivation
This lib was created with the purpose of making it easier to implement APIs that are fully compliant with the [EIP-3668](https://eips.ethereum.org/EIPS/eip-3668) specification.
Its differential is that it is capable of handling middlewares per function by attaching any given number of endpoints to an Express router.
## Usage
The supported request looks like the following:
```shell
# abi.encodeWithSelector(0x59d1d43c, 'com.twitter', '@blockful')
CALLDATA='0x59d1d43c194774734a8c16665005fd2c68cb7cc80b5aa6ffcb0c56ace654bc614902cf7f00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000008626c6f636b66756c000000000000000000000000000000000000000000000000'
curl -X GET http://127.0.0.1/0x6AEBB4AdC056F3B01d225fE34c20b1FdC21323A2/$(CALLDATA)
curl -X POST http://127.0.0.1 -H "Content-Type: application/json" \
-d '{"sender": "0x6AEBB4AdC056F3B01d225fE34c20b1FdC21323A2", "calldata": $(CALLDATA)}'
```
### Single handler with no middlewares
```ts
const handlers : FunctionHandler[] = [
{
signature: 'function text(bytes32 node, string key) view returns (string)',
handlers: [
(_: Request, res: Response, __: NextFunction) => {
const { node, key } = res.locals
res.json({ node, key })
}
]
}
]
app.use(CCIPHandler(handlers))
```
### Multiple handlers with not middlewares
```ts
const handlers : FunctionHandler[] = [
{
signature: 'function text(bytes32 node, string key) view returns (string)',
handlers: [
(_: Request, res: Response, __: NextFunction) => {
const { node, key } = res.locals
res.json({ node, key })
}
]
},
{
signature: 'function setText(bytes32 node, string calldata key, string calldata value)',
handlers: [
(_: Request, res: Response, __: NextFunction) => {
const { node, key } = res.locals
res.json({ node, key })
}
]
}
]
app.use(CCIPHandler(handlers))
```
### Single handler with middlewares
```ts
const handlers : FunctionHandler[] = [
{
signature: 'function text(bytes32 node, string key) view returns (string)',
handlers: [
(_: Request, res: Response, next: NextFunction) => {
next()
},
(_: Request, res: Response, __: NextFunction) => {
const { node, key } = res.locals
res.json({ node, key })
},
(_: Request, res: Response, next: NextFunction) => {
next()
},
]
}
]
app.use(CCIPHandler(handlers))
```