Mevlink streamer-go

A golang streaming library for Mevlink's transaction streaming service

To quickly get started using streamer-go check out the Getting Started section.

Description

The streamer connects to a TCP socket on the lowest-latency Mevlink node and authenticates itself via HMAC challenge-response with your API key and ID.

For each transaction we forward to you, you'll get:

  • The raw rlp-encoded transaction bytes

  • The nullable transaction hash (when using the latest version)

  • The time at which the Mevlink node first learned of the transaction's existence (for example, via a NEW_POOLED_TRANSACTION_HASHES request)

  • The time at which the Mevlink node sent the transaction to you over the TCP stream

The binary streaming API is deliberately simple; if you are interested in learning how it works, feel free to read the comments. The ordering of the emitted fields, timing information, and MAC is such that you can choose to consider/respond to transactions before you have timing information or have verified the authentication signature.

The stream gives no guarantee of transactions being valid or will be successfully processed on-chain by BSC fullnodes; it simply provides transaction that have been seen via P2P node connections. Stay sharp, and verify what you need to.

Example

Here's a quick snippet to get you started with the streamer-go library:

// mevlink/stream.go

package main

import (
	"encoding/hex"
	"log"
	"time"

	mlstreamer "github.com/mevlink/streamer-go"
	"golang.org/x/crypto/sha3"
)

func main() {

    // create streamer
    var str = mlstreamer.NewStreamer("<api-key-id>", "<api-key-secret>", 1)
    
    // transaction callback
    str.OnTransaction(func(txb []byte, hash mlstreamergo.NullableHash, noticed time.Time, propagated time.Time) {
        //Getting the transaction hash and printing the relevant times
        var hasher = sha3.NewLegacyKeccak256()
        hasher.Write(txb)
        var tx_hash = hasher.Sum(nil)

        log.Println("Got tx '" + hex.EncodeToString(tx_hash) + "'! Was noticed on ", noticed, "and sent on", propagated)
    })

    log.Fatal(str.Stream())
}

Last updated