Django Ethereum Events
Project description
Ethereum Contract Event Log monitoring in Django
Overview
This package provides an easy way to monitor an ethereum blockchain for transactions that invoke Contract Events that are of particular interest.
The main concept was inspired by the following project:
Installation
Either checkout django-ethereum-events from GitHub, or install using pip:
pip install django-ethereum-events
Make sure to include 'django_ethereum_events' in your INSTALLED_APPS
INSTALLED_APPS += ('django_ethereum_events')
Make necassery migrations
python manage.py makemigrations django_ethereum_events
Usage
In your settings file, specify the following settings
ETHEREUM_NODE_HOST = 'localhost' ETHEREUM_NODE_PORT = 8545 ETHEREUM_NODE_SSL = False ETHEREUM_EVENTS = []
ETHEREUM_EVENTS parameter is a list of that holds information about the specific events to monitor for. Its syntax is the following
ETHEREUM_EVENTS = [ { 'CONTRACT_ADDRESS': 'contract address', 'EVENT_ABI': 'abi of the event(not the whole contract abi)', 'EVENT_RECEIVER': 'custom event handler' } ]
Create an appropriate EVENT_RECEIVER
from django_ethereum_events.chainevents import AbstractEventReceiver class CustomEventReceiver(AbsractEventReceiver): def save(self, decoded_event): # custom logic goes here
The decoded_event parameter is the decoded log as provided from web3.utils.events.get_event_data method.
To start monitoring the blockchain, either run the celery task django_ethereum_events.tasks.event_listener or better, use celerybeat to run it as a periodical task
from celery.beat import crontab CELERYBEAT_SCHEDULE = { 'ethereum_events': { 'task': 'django_ethereum_events.tasks.event_listener', 'schedule': crontab(minute='*/5') # run every 5 minutes } }
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for django_ethereum_events-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54da9c2b4b675c329f9733505a3b20640138f511e450acd51a285b12fc72721f |
|
MD5 | 3f9f93ba38255508d613bdbcd84677e1 |
|
BLAKE2b-256 | 2068f20a79e1bc0b747bd5ff413bfbf4dc24c812a066c1980dae9a6e5fd1469a |