This repository is now deprecated.
The Direct Route service is no longer supported.
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.
Direct Route achieves following goals:
- Transaction privacy. Transactions submitted through Direct Route can never be detected by others before they have been included in a block.
- First-price sealed-bid auction. It allows users to privately communicate their bid and granular transaction order preference.
- 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.
- 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.
- Efficiency. Bundle is performed without causing unnecessary network or chain congestion.
Go version above 1.16
Add github.com/node-real/go-direct-route
dependency into your go.mod file. Example:
require (
github.com/node-real/go-direct-route latest
)
var directRouteEndPoint = "https://api.nodereal.io/direct-route"
client, _ := client.Dial(directRouteEndPoint)
- Query suggested bundle price
price, _ := client.BundlePrice(context.Background())
- 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.
- Query bundle
bundle, _ := directClient.GetBundleByHash(context.Background(), bundleHash)
You can try Direct-Route Testnet by changing the endpoint to: https://testnet-api.nodereal.io/direct-route
Please note you should use the BSC testnet RPC and use testnet chainId(97) when sign the transaction.
If you want to increase your Bundle Price, you can use this contract, which will transfer your provided BNB to the coinbase responsible for mining your bundle.
please refer the sendBNBByBundleWithDepositCoinbaseDemo()
in example.go.
- mainnet:
0xB3BB00B9785f35D0BE13B2BD91C8e3742D9Ab03a
- testnet:
0xE7febD44315508a1100E1a06701e7e0Ae5e325Bc
We provide three demos in example.go
:
getBundlePriceDemo
. The bundle price is volatile according to the network congestion, the demo shows you how to get proper bundle price.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.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.sendBNBByBundleWithDepositCoinbaseDemo()
. In this case, we use two different accounts to send BNB to each other, and including deposit BNB to coinbase to increase Bundle Price the two transactions should be all successful or all failed.
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