Send email notifications when a contract event is emitted
Go to file
dependabot[bot] 9b5de5d59e
Bump json5 from 1.0.1 to 1.0.2
Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-07 11:52:40 +00:00
api Update utils.js 2020-01-24 14:22:53 -04:00
config Add valid dapps to config 2019-11-18 14:59:25 -04:00
dapps/teller-network Update config.js 2020-01-16 19:26:26 -04:00
mail Markdown support for email templates 2019-11-26 19:07:17 -04:00
models Email confirmation and templates 2019-11-14 16:01:31 -04:00
tests fix: filters 2020-01-03 12:02:57 -04:00
watcher fix: email config 2020-01-16 16:23:46 -04:00
.gitignore Error logging 2019-11-18 11:50:39 -04:00
.prettierrc Extract controller code 2019-11-15 10:42:59 -04:00
LICENSE Initial commit 2019-11-13 10:53:25 -04:00
README.md Add valid dapps to config 2019-11-18 14:59:25 -04:00
dapp-config.js fix: variable name 2020-01-02 16:34:40 -04:00
dapp-schema.js Add 'variables' to schema 2020-01-02 16:23:26 -04:00
database.js Error logging 2019-11-18 11:50:39 -04:00
logger.js Error logging 2019-11-18 11:50:39 -04:00
package.json Markdown support for email templates 2019-11-26 19:07:17 -04:00
yarn.lock Bump json5 from 1.0.1 to 1.0.2 2023-01-07 11:52:40 +00:00

README.md

Contract notifier

Opt-in service to send email notifications when a contract event is emitted

Requirements

  • NodeJS (tested on node v10.16.0)
  • MongoDB
  • Yarn (recommended)

Installation

git clone https://github.com/status-im/contract-notifier
cd contract-notifier
yarn

Usage

Configuration

General

./config/index.js

  • PORT: port where the API will be available (default: 4000)
  • RATE_LIMIT_MAX_REQ: Max number of connections during RATE_LIMIT_TIME milliseconds before sending a 429 response. (default: 1)
  • RATE_LIMIT_TIME: How long in milliseconds to keep records of requests in memory. (default: 15)
  • DB_CONNECTION: MongoDB connection string
  • BLOCKCHAIN_CONNECTION_POINT: URL string of an ethereum node. (default: http://localhost:8545)
  • SENDGRID_API_KEY: To send emails.
  • BLOCK_DELAY: Adds a delay in the number of blocks to avoid reorgs. (default: 6)
  • POLL_SLEEP: Interval of time wait for polling the chain for new events. (default: 30)
  • VALID_DAPPS: Array with known dapps in dapps/ folder

The ENV variable can be used to set these variables, as well as a .secret.json file.

Dapp

Each dapp should have their own configuration and templates to send emails. To add a dapp, create a folder inside ./dapps/ with the dapp name. Also, edit ./config/index.js to add the new dapp in VALID_DAPPS. (This will change with a proper dapp registry, to avoid this manual process)

Each dapp folder should have a config.js file and one or more .html and .txt templates. See ./dapps/teller-network/config.js for a sample config.

(TODO: document the config file)

Execution

  • To launch the API endpoint:
yarn api

API will be available in http://localhost:4000 or whatever port was configured

  • To launch the contract events mailer:
yarn watch

Rest API

The following methods are available in the API:

Subscribe

{
  "email": "user@email.com",
  "address": "0x1234...ABCD",
  "signature": "0x1234...ABCD"
}
  • Signature must be the user's email signed by the address
  • Replies with OK if the subscription was successful. Otherwise, an error message is shown
  • Sends a signup email with a token that expires in 2hr.
  • :dappId must be known by the service.

Verify

Unsubscribe

{
  "address": "0x1234...ABCD",
  "signature": "0x1234...ABCD"
}
  • Signature must be the :dappId signed by the address
  • Replies with OK if the user is unsubscribed successfully. Otherwise, an error message is shown
  • :dappId must be known by the service.

User exists

Contribution

Thank you for considering to help out with the source code! We welcome contributions from anyone on the internet, and are grateful for even the smallest of fixes!

If you'd like to contribute to this project, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base. If you wish to submit more complex changes though, please check up with the core devs first on #embark-status channel to ensure those changes are in line with the general philosophy of the project and/or get some early feedback which can make both your efforts much lighter as well as our review and merge procedures quick and simple.

License

MIT