Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 2.78 KB

README.md

File metadata and controls

45 lines (31 loc) · 2.78 KB

Ethbase

Gitter chat

The aim of this project is to provide a mechanism for enabling smart contracts to subscribe to events emitted in other contracts. For a short description of the why and how of this project, you can refer to the about wiki page.

Events are submitted to the network by relayers. To make the process trustless, relayers provide MPT proofs that the event log they're submitting has been included in the receipts trie of a recent block (last 256 blocks).

Note: Ethbase is currently in a very early development and experimental stage, and is not suitable for production use.

Rinkeby: 0x2ccf778b371e24010b6733a377e999844bdc114a

Usage

In the given example, we have an Emitter contract, which emits Transfer(uint256) when its method is called. We want our Subscriber contract to update its state, whenever Transfer is emitted. This can be done, by subscribing to the registry, and specifying the target event and the callback method that should be executed when the event is emitted. Afterwards, any relayer, upon seeing a Transfer event, can call submitLog on Ethbase, which would in turn invoke Subscriber's specified method.

To subscribe to an event, you can create an instance of Ethbase and call subscribe in your smart contract:

ethbase = Ethbase(ethbase);
ethbase.subscribe(emitter, eventTopic, subscriber, method);
  • emitter is the address of the contract that emits the event.
  • eventTopic is the topic you're interested in, e.g. keccak256("Transfer(uint256)").
  • subscriber the contract that should be called when event is emitted, e.g. this.
  • method the method that should be called. Method must have the same signature as the event, and generated by bytes4(keccak256("METHOD_NAME(TYPE1,TYPE2)")).

Contribute

Most of the discussions are happening in the issues and pull requests, Suggestions, contributions and critisisms are more than welcome, join in.

If you want to get involved: first of all, thanks for considering to do so! Here's how you can setup your environment:

Requirements

Node is the only thing you need. After cloning the repository, install the dependencies, and build the contracts.

$ npm i
$ npx truffle compile

Tests

To run the contracts test suite:

$ npx truffle test