Code Monkey home page Code Monkey logo

go-blocknative's Introduction

go-blocknative

go-blocknative provides an api client for blocknative's websocket api. It allows subscribing to events by address or by transaction id and handles correct initialization as required by the documentation. It also includes the ability to store commands sent to the api in a history buffer, such that in the event of a connection failure we can restablish the current session as blocknative does not handle this on their end.

Usage

This library provides functionality to subscribe to events from blocknatives API using either transaction hashes or addresses. In addition it provides a number of different message types as indicated below

Message Types

BaseMessage

The BaseMessage struct contains all required fields that need to be sent in messages to blocknative's API. To easily construct new base messages for the mainnet you can use NewBaseMessageMainnet("yourApiKey").

TxSubscribe

The TxSubscribe struct is used when subscribing/unsubscribing to events by transaction hash. If you want to send a message to subscribe to events use NewTxSubscribe supplying a base message along with the transaction hash to subscribe to. If you want to send a message to unsubscribe from events use NewTxUnsubscribe supplying a base message along with the transaction hash to unsubscribe from

AddressSubscribe

The AddressSubscribe struct is like TxSubscribe but allows subscribing/unsubscribing to events by ethereum account addresses. If you want to send a message to subscribe to events use NewAddressSubscribe supplying a base message along with the address to subscribe to. If you want to send a message to unsubscribe from events use NewAddressUnsubcribe.

EthTxPayload

When subscribe to events the EthTxPayload will be returned anytime an event is received for a transaction or address we are subscribed to. It is suitable for generalized processing of events, however you will likely want to use a use-case specific structure for better processing. Depending on the contract events being emitted they may have more information that what can be captured by this structure.

Examples

The examples folder has some full running examples. Note that you should be familiar with the mechanics of github.com/gorilla/websockets as this library essentially just provides helper functions around the websockets library

TODO

  • Enable message history buffer usage
  • Enable connection drop handling
  • Enable better error handling
  • Enable optional payload and subscription parameters
  • Enable configuration usage

go-blocknative's People

Contributors

bonedaddy avatar krasi-georgiev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.