Transaction Stream
Setting up Mevlink to get a transaction stream wherever you need it
In your project, make a new directory mevlink
and a file called stream.go
. This is where we will import and set up streamer-go.
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
Imports
First we'll import streamer-go
as mlstreamer
plus some other packages we'll be making use of to parse the incoming transaction bytes.
Create Streamer
Then in main
we'll set up the mlstreamer using the API key credentials you can find here once you've created an account. The API Key Secret is only shown once during the creation of your API Key.
In the example above, the third parameter, 1
represents the network id for which you want to receive and emit transactions. Currently we only support two networks:
Transaction Callback
Use the transaction callback to perform some action (like adding the transaction to Geth's transaction pool) every time you receive a transaction:
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.
In the case that you have your own custom transaction cache, you can also use the transaction hash field to check your cache without having to decode the transaction bytes.
At this point, you can do whatever you'd like with the transaction. However, be aware that the transaction itself has not been verified on our end and the node stream gives no guarantee of transactions being valid or that they will be successfully processed on-chain. All it does is provide transaction that have been seen via P2P node connections.
To verify them using geth or a geth fork, you can add them to geth's transaction pool and check for validation errors. We'll go over one way of doing that in the step.
Full Snippet
Here's a quick and simple example of how you can use streamer-go. Make sure to replace the <api-key-id>
and <api-key-secret>
with your own credentials after signing up and purchasing a plan on mevlink.com.
Output
Here's an example of a transaction log we get using the snippet above:
Last updated