This package implements a simple CCIP-read gateway worker for ENS offchain resolution.
Before running the gateway worker, couple of configuration needs to be done as following;
- Create a
dev.vars
file underpackages/gateway-worker/
folder - Put gateway private key into it in between double quotes, as below;
OG_PRIVATE_KEY="PRIVATE_KEY_HERE"
- Run addToKV.js script to write test.eth.json file into Cloudflare KV Store
node addToKV.js -d test.eth.json
- Run worker;
yarn && yarn build
yarn start
private-key
should be an Ethereum private key that will be used to sign messages. You should configure your resolver contract to expect messages to be signed using the corresponding address.
data
is the path to the data file; an example file is provided in test.eth.json
.
- Be sure all configurations mentioned in local section are in place.
- Add private key as a Cloudflare Secret with OG_PRIVATE_KEY key.
- Deploy worker with
wrangler publish
The JSON backend is implemented in json.ts, and implements the Database
interface from server.ts. You can replace Cloudflare KV Store with your own database service by implementing the methods provided in that interface. If a record does not exist, you should return the zero value for that type - for example, requests for nonexistent text records should be responded to with the empty string, and requests for nonexistent addresses should be responded to with the all-zero address.
For an example of how to set up a gateway server with a custom database backend, see index.ts:
const signer = new ethers.utils.SigningKey(privateKey);
const db = JSONDatabase.fromKVStore(OFFCHAIN_STORE_DEV, parseInt(OG_TTL));
const app = makeApp(signer, '/', db);
module.exports = {
fetch: function (request, _env, _context) {
return app.handle(request)
}
};