This monorepo contain package that aims to maintain name-to-address and address-to-name cache that is updated in realtime. Also, here you can find simple web service that uses this package to provide REST API for name and address resolution.
To start service do following:
- Clone repository
- Run
npm install --foreground-scripts - Run
lerna bootstrap - Copy
.env.examplefile to.envand setREDIS_URL,ETH_NETWORKandWEBSOCKET_URL. For theWEBSOCKET_URLspecify a blockchain node, for example Infura. Websocket is preferred over HTTP for massive indexing performance. Note that we don't recommend Alchemy API as it is known to cause errors.
Note Currently only mainnet and goerli networks are supported.
For more technical details regarding cache check dweb-live-cache package readme. In following sections we will cover how to start and use simple cache web service.
There is packages/dweb-live-cache/seed_data directory that contains JSON files with seed data pulled from specific ETH network at specific block number.
This allows to skip indexing all blocks since resolver contracts were deployed.
Before seeding DB make sure that .env file is configured properly.
To seed DB run npm run seed command.
To start service run npm start command. Service will start indexing AddrChanged(bytes32,address) and
NameChanged(bytes32,string) events on PublicResolver and DefaultReverseResolver contracts.
Indexing starts from last indexed block number. If there is no data in DB service will start indexing from block number
specified in constants.ts. This is number of block when PublicResolver and
DefaultReverseResolver were deployed.
As the service indexing block it listens for block events on provider to keep track of every new block.
If service is crashed or stopped it will continue indexing from last indexed block number.
Resolution uses Redis to store name and address cache. To force cache refresh simply add refresh=1 to querystring.
curl --location --request GET 'http://localhost:3000/name/serhii'Sample response:
{
"success": true,
"result": "0x13BCb838DAEFF08f4E56237098dB1d814eeB837D"
}Request:
curl --location --request POST 'http://localhost:3000/name/batch' \
--header 'Content-Type: application/json' \
--data-raw '[
"serhii", "mauvis"
]'Sample response:
{
"success": true,
"result": [
{
"name": "serhii",
"success": true,
"address": "0x13BCb838DAEFF08f4E56237098dB1d814eeB837D"
},
{
"name": "mauvis",
"success": true,
"address": null
}
]
}curl --location --request GET 'http://localhost:3000/address/0x13BCb838DAEFF08f4E56237098dB1d814eeB837D'Sample response:
{
"success": true,
"result": {
"name": "serhii",
"confirmed": true
}
}Request:
curl --location --request POST 'http://localhost:3000/address/batch' \
--header 'Content-Type: application/json' \
--data-raw '[
"0x13BCb838DAEFF08f4E56237098dB1d814eeB837D",
"0x6B7F15b87337a180b744B926Ed017A2D81A1d752"
]'Sample response:
{
"success": true,
"result": [
{
"address": "0x13BCb838DAEFF08f4E56237098dB1d814eeB837D",
"success": true,
"name": "serhii",
"confirmed": true
},
{
"address": "0x6B7F15b87337a180b744B926Ed017A2D81A1d752",
"success": true,
"name": "lordsats",
"confirmed": true
}
]
}