Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bonedaddy/go-blocknative
blocknative websocket api client in golang
https://github.com/bonedaddy/go-blocknative
blockchain blocknative blocknative-api defi ethereum ethereum-events golang smart-contracts websockets
Last synced: 2 months ago
JSON representation
blocknative websocket api client in golang
- Host: GitHub
- URL: https://github.com/bonedaddy/go-blocknative
- Owner: bonedaddy
- License: apache-2.0
- Created: 2021-01-28T20:49:37.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-16T17:54:07.000Z (over 2 years ago)
- Last Synced: 2024-11-02T03:50:31.763Z (3 months ago)
- Topics: blockchain, blocknative, blocknative-api, defi, ethereum, ethereum-events, golang, smart-contracts, websockets
- Language: Go
- Homepage:
- Size: 177 KB
- Stars: 31
- Watchers: 4
- Forks: 23
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# 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
## AddressSubscribeThe `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