The Direct Route GO SDK provides a thin wrapper around the Direct Route API for sending private transactions

Direct Route Go SDK

The Direct Route GO SDK provides a thin wrapper around the Direct Route API for sending private transactions. It includes the following core components:

  • client - implementations of Direct Route client, such as for querying bundle price, sending bundles.
  • example - provide examples about how to using Direct Route in many different scenarios.

What is Direct Route

Direct Route achieves following goals:

  1. Transaction privacy. Transactions submitted through Direct Route can never be detected by others before they have been included in a block.
  2. First-price sealed-bid auction. It allows users to privately communicate their bid and granular transaction order preference.
  3. No paying for failed transactions. Losing bids are never included in a block, thus never exposed to the public and no need to pay any transaction fees.
  4. Bundle transactions. Multiple transactions are submitted as a bundle, the bundle transactions are all successfully validated on chain in the same block or never included on chain at all.
  5. Efficiency. Bundle is performed without causing unnecessary network or chain congestion.

Install

Requirement

Go version above 1.16

Use go mod(recommend)

Add github.com/node-real/go-direct-route dependency into your go.mod file. Example:

require (
	github.com/node-real/go-direct-route latest
)

Init Client

var directRouteEndPoint = "https://api.nodereal.io/direct-route"
client, _ := client.Dial(directRouteEndPoint)

Quick Start with APIs

  1. Query suggested bundle price
price, _ := client.BundlePrice(context.Background())
  1. Send bundle
	data1, _ := bep20ABI.Pack("transfer", account2.Addr, big.NewInt(1))
	data2, _ := bep20ABI.Pack("transfer", account2.Addr, big.NewInt(1))

	tx1, hash1, _ := utils.SignTransaction(account1, common.HexToAddress("0xe9e7cea3dedca5984780bafc599bd69add087d56"), valueToTransfer, data1, n1, gasLimit, price, chainId)
	tx2, hash2, _ := utils.SignTransaction(account1, common.HexToAddress("0xe9e7cea3dedca5984780bafc599bd69add087d56"), valueToTransfer, data2, n1+1, gasLimit, price, chainId)
	maxTime := uint64(time.Now().Unix() + 80)
	minTime := uint64(time.Now().Unix() + 20)

	bundle := &client.SendBundleArgs{
		Txs:               []string{hexutil.Encode(tx1), hexutil.Encode(tx2)},
		MaxBlockNumber:    "",
		MinTimestamp:      &minTime,
		MaxTimestamp:      &maxTime,
		RevertingTxHashes: []common.Hash{hash2},
	}
	bundleHash, err := directClient.SendBundle(context.Background(), bundle)

After the bundle is successfully submitted, you may need wait at lest 3-60 seconds before the transaction been verified on chain.

So please use MaxBlockNumber and MaxTimestamp a relative lager one, better 60 seconds later, otherwise Direct Route may get no chance to include the bundle.

Note that only one tx sender is allowed with one bundle.

  1. Query bundle
bundle, _ := directClient.GetBundleByHash(context.Background(), bundleHash)

SDK Example

We provide three demos in example.go:

  1. getBundlePriceDemo. The bundle price is volatile according to the network congestion, the demo shows you how to get proper bundle price.
  2. sendBNBByBundleDemo. In this case, we use two different accounts to send BNB to each other, the two transaction should be all successful or all failed.
  3. sendBUSDByBundleDemo. In this case, we use two accounts to send BUSD to each other, the second transaction is allowed to be failed, and the bundle should be verified on chain during [now+20 second, now+80 second]. This case shows you how to interact with smart contract through direct-route, and how to control the timing to be verified.

If you want to try with above examples, what you need to do is just to replace the private keys of account1 and account2 in example.go

Comments
  • add new fields in bundle response

    add new fields in bundle response

    add two new fields in bundle response:

    • Status: status of bundle, 1: bundle sent, 2: bundle included in block, 3: bundle failed
    • ErrMsg: the error msg when bundle failed
  • [R4R] update api && example

    [R4R] update api && example

    The DR update new feature of price calculations :

    1. Support for new price calculations.
    2. Add example of sending bundle with deposit coinbase.

    The readme and example changed accordingly.

  • go get err

    go get err

    github.com/node-real/go-direct-route: module github.com/node-real/go-direct-route@latest found (v1.0.0), but does not contain package github.com/node-real/go-direct-route

  • [R4R] add new fields in bundle query response

    [R4R] add new fields in bundle query response

    add two new fields in bundle response:

    • Status: status of bundle, 1: bundle sent, 2: bundle included in block, 3: bundle failed
    • ErrMsg: the error msg when bundle failed
  • !!BUG!!

    !!BUG!!

    You said 3 demo will send BNB and token each other. But I noticed that it will send only from one account to another account. It is impossible to send each other. image

  • how many validator joined?

    how many validator joined?

    hi, it's very similar to flashbots in ethereum, I have several questions in my mind:

    1. how many validator joined the network?
    2. in the example it's just simple bnb/token transfer and no bribe paid, but in real case , it is need arbitrage keeper to pay bribe for get the opportunity right?
    3. does BSC validator allowed to do this?
Goal is a toolkit for high productivity web development in Go language in the spirit of Revel Framework that is built around the concept of code generation.

Goal Goal is a set of tools for high productivity web development in Go language. Goal, being mostly inspired by Revel Framework and its discussions,

Sep 27, 2021
GoPrisma - A Go wrapper for prisma to turn databases into GraphQL APIs using Go.

GoPrisma - a Go wrapper for the Prisma Engines What's this? Introspect a database and use it as a GraphQL API using Go. Supported Databases: SQLite Po

Dec 20, 2022
Data injection wrapper for values maintained in a GCP Secret Manager document.

injector The injector is a utility that retrieves a GCP Secret Manager document which contains an HJSON or JSON object with an embedded top-level envi

Jan 19, 2022
This library provides a simple framework of microservice, which includes a configurator, a logger, metrics, and of course the handler

Microservice The framework for the creation of microservices, written in Golang. (note: http microservice) Architecture microservice includes: handle

Dec 30, 2022
This package provides a generic way of deep copying Go objects

Package for copying Go values This package provides a generic way of deep copying Go objects. It is designed with performance in mind and is suitable

Nov 9, 2022
RPC Framework abstraction layer. Provides foundation of the RonyDesc to generate RPC server/client codes.

RonyKit RonyKit provides the abstraction layer for creating a cluster aware API server. By defining separate components for each task, you are almost

Dec 15, 2022
弹弹play 资源搜索节点 API 实现,基于 Cloudflare Workers 或 Golang 的两种实现。 || API implementations for "dandanplay" resource search service.

dandanplay-resource-service API implementations for "dandanplay" resource search service. 弹弹play 资源搜索节点的 API 实现。 提供基于 Cloudflare Workers 和 Golang 的两种实

Dec 5, 2022
Couper is a lightweight API gateway designed to support developers in building and operating API-driven Web projects
Couper is a lightweight API gateway designed to support developers in building and operating API-driven Web projects

Couper Couper is a lightweight API gateway designed to support developers in building and operating API-driven Web projects. Getting started The quick

Nov 18, 2022
REST API made using native Golang libraries. This API resembles the basic working of Instagram.
REST API made using native Golang libraries. This API resembles the basic working of Instagram.

Golang RESTful API for Instagram A Go based REST API built using native libraries. The API has been thoroughly worked through with Postman. Routes inc

Mar 16, 2022
Boilerplate API template includes all the common packages and setup used for API development in this Company

Boilerplate API Boilerplate API template includes all the common packages and setup used for API development in this Company. Development Copy .env.ex

Feb 19, 2022
A quick and easy way to setup a RESTful JSON API

Go-Json-Rest A quick and easy way to setup a RESTful JSON API Go-Json-Rest is a thin layer on top of net/http that helps building RESTful JSON APIs ea

Jan 3, 2023
golang crud restful api with gorm , gin and mysql DB

crud restful api with golang , gorm , gin and mysql this api does a simple CRUD operations on a single table mysql Database . this is build on top off

Feb 26, 2022
Opinionated Go starter with gin for REST API, logrus for logging, viper for config with added graceful shutdown

go-gin-starter An opinionated starter for Go Backend projects using: gin-gonic/gin as the REST framework logrus for logging viper for configs Docker f

Dec 2, 2022
A Go REST API allowing me to send messages to myself, on my phone, according to some events.
A Go REST API allowing me to send messages to myself, on my phone, according to some events.

go-telegram-notifier go-telegram-notifier A Go REST API wrapping the official Telegram API and used to send myself notifications, on my phone, based o

Apr 27, 2022
TeslaMateApi is a RESTful API to get data collected by self-hosted data logger TeslaMate in JSON

TeslaMateApi is a RESTful API to get data collected by self-hosted data logger TeslaMate in JSON.

Dec 10, 2022
Mattermost Posts via its REST API v4
Mattermost Posts via its REST API v4

A Go (golang) simple client for sending Mattermost posts via its REST API v4. This program makes use of the Go libraries http and url for interacting with a Mattermost server and Cobra coupled with Viper to implement the CLI interface.

Dec 1, 2022
CRUD API server of Clean Architecture with Go(Echo), Gorm, MySQL, Docker and Swagger
CRUD API server of Clean Architecture with Go(Echo), Gorm, MySQL, Docker and Swagger

CRUD API Server of Clean Architecture Go(echo) gorm mysql docker swagger build docker-compose up -d --build API Postman and Fiddler is recommended to

May 14, 2022
Tigo is an HTTP web framework written in Go (Golang).It features a Tornado-like API with better performance. Tigo是一款用Go语言开发的web应用框架,API特性类似于Tornado并且拥有比Tornado更好的性能。
Tigo is an HTTP web framework written in Go (Golang).It features a Tornado-like API with better performance.  Tigo是一款用Go语言开发的web应用框架,API特性类似于Tornado并且拥有比Tornado更好的性能。

Tigo(For English Documentation Click Here) 一个使用Go语言开发的web框架。 相关工具及插件 tiger tiger是一个专门为Tigo框架量身定做的脚手架工具,可以使用tiger新建Tigo项目或者执行其他操作。

Jan 5, 2023