bloXroute Documentation
WebsiteBlogTwitterDiscord
  • Welcome to bloXroute
  • Introduction
    • Why Use bloXroute?
    • Products
    • Create An Account
    • Technical Support
  • SOLANA
    • Trader API
      • Introduction
        • Regions
        • Authorization
        • Rate Limits
        • Tip and Tipping Addresses
      • Quick Start
        • Transaction Submission
        • Front-Running Protection & Transaction Bundle
        • Go SDK
        • Python SDK
        • Typescript SDK
        • Rust SDK
      • API Endpoints
        • Core Endpoints
          • submit
          • submit-paladin
          • submit-batch
          • balance
          • rate-limit
          • transaction
          • priority-fee
          • GetPriorityFeeStream
          • GetBundleTipStream
          • submit-snipe
        • Pump.fun
          • quotes
          • swap
          • swap-sol
          • GetPumpFunNewTokensStream
          • GetPumpFunSwapsStream
          • GetPumpFunAMMSwapsStream
        • Raydium
          • quotes
          • pools
          • pool-reserves
          • swap
          • cpmm-swap
          • clmm-swap
          • route-swap
          • GetPoolReservesStream
          • GetSwapsStream
          • GetNewRaydiumPoolsStream
          • GetNewRaydiumPoolsByTransactionStream
        • Jupiter
          • quotes
          • swap
          • swap-instructions
          • route-swap
        • Openbook
          • markets
          • orderbooks/{market}
          • depth/{market}
          • tickers/{market}
          • open-orders/{market}
          • unsettled/{market}
          • place
          • replace
          • cancel
          • settle
          • GetOrderbooksStream
          • GetTickersStream
      • Best Performance for Landing Transactions
      • Support
        • API Health
        • Contact us
        • Suggestions
        • Wiki
          • Terms & Concepts
          • Resources
    • Optimized Feed Relay (OFR)
      • Transaction Streamer
      • Gateway and OFR Requirements
      • Gateway and OFR Setup
      • Gateway Startup Arguments
      • OFR performance
      • Logging
      • Submitting Transaction
      • Upgrading Gateway
      • Troubleshooting
  • BSC & ETH
    • EVM Blockchain Distribution Network (BDN)
      • How to Connect
      • The bloXroute Gateway
        • Local Gateway
          • Installation and Startup
            • Authentication & Certificates
            • Requirements
            • Supported Clients
            • GitHub repository option
            • Docker container option
            • Startup Script
            • Startup Arguments
          • General Connectivity Troubleshooting
          • Logging
          • Upgrading your Gateway
        • Add Your Gateway as a Trusted Peer to Your Execution Layer Client
        • Connecting Your Gateway with the Consensus Layer
      • IPs & Relays
        • Relays IPs
        • Private Relays
        • Cloud-API IPs
          • ⏩Reducing Latencies using the BDN
    • APIs
      • Authorization
      • Check Transaction Quota
      • Submit a Transaction
        • Raw Transaction Construction
        • Tx-Validation
        • Batch Transaction
      • Private Transactions
        • ETH Private Transactions
        • BSC Private Transactions
      • Transaction Bundles
        • Bundle Simulation
        • Bundle Validation
        • Bundle Submission
          • BSC Bundle Submission
            • List of BSC Validators
          • ETH Bundle Submission
          • Bundle Submission with Gateway
        • Bundle Tracking
          • BSC Bundle-Trace
          • ETH Bundle-Trace
          • ETH Bundle Inclusion Status
        • Bundle Refunds
          • Priority Fee Refund
          • Bundle Refund
          • Latest Bundle Refunds
      • Backrun Arbitrage
        • BackRunMe: Bundle Submission
          • BSC submit arbOnly
          • ETH submit arbOnly
            • blxr_info
            • ETH arbOnly Simulation
      • Token Launch Sniping
      • Other Utilities
        • List of bloXroute Builders
        • List of External Builders
        • Tx-Trace
        • Ping
    • Streams
      • Requirements
      • Subscription limits
      • Working With Streams
        • Creating a Subscription
          • Websocket
          • gRPC
        • Handling the Notification
          • Websocket
          • gRPC
        • Cancelling a Subscription
          • Websocket
          • gRPC
        • Local Node Validation
      • newTxs and pendingTxs
        • Filters
        • Raw TX Reconstruction
      • BackRunMe: arbOnlyMEV
        • ETH arbOnlyMEV
        • BSC arbOnlyMEV
      • transactionStatus
      • txReceipts
      • newBlocks
      • bdnBlocks
      • ethOnBlock
      • MEVBlockValue
      • MEVNextProposerInfo
    • Block Builders and Validators
      • Validator Gateway
      • MEV Relay (For Validators)
      • Block Submission
      • Proposer MEV-Protect
      • Compliance Lists
      • Preconfirmations
    • Protect RPCs
      • ETH Protect RPC
      • ETH Gas Protect RPC
      • BSC Protect RPC
      • SOL Protect RPC
  • Base Network
    • Submit Transactions
    • Streams
      • GetBdnBlockStream
  • TON NETWORK
    • TON Trader API
      • Quick Start
      • Fee Schedule
      • Connection
      • Submit Signed Transaction
  • Resources
    • BDN Explorer
    • Block Explorer
    • Guides
      • Algorithmic Trading
      • Setting Up a Local Gateway
      • Gateway as Web3 Bridge
    • Architecture
      • BDN Architecture
        • Network Components
        • Performance Techniques
          • Block Compression
          • Cut-through Routing
          • Optimized Topology
      • bloXroute Protocol
        • Versioning
        • Message Structure
        • Message Types
    • Contact Us
Powered by GitBook
On this page
  1. BSC & ETH
  2. Intent Network
  3. Examples

Submit quote

This example demonstrates how to submit an quote using the bloXroute Gateway gRPC API.

Name: SubmitQuote

SubmitQuote is a GRPC method that propagates quote to the BDN. SubmitQuoteRequest arguments:

Key
Description
Values

dappAddress

ETH address of the DApp that should receive quote

string

solverAddress

ETH address of the quote solver

string

qoute

quote payload

byte[]

hash

Keccak256Hash of the quote payload

byte[]

signature

ECDSA signature of the hash

byte[]

SubmitQuoteReply fields:

Key
Description
Values

quoteId

UUID of the quote

string

first_seen

timestamp when quote was first seen in BDN (for now empty)

google.protobuf.Timestamp

Examples - gRPC

package main

import (
	"context"
	"encoding/hex"
	"fmt"
	"log"

	pb "github.com/bloXroute-Labs/gateway/v2/protobuf"

	"github.com/ethereum/go-ethereum/crypto"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials"
)

// dAppAddr is the dApp addr of the quote
const dAppAddr = "<addr>"

// gatewayHost is the address of the gateway to which the quote is being submitted
const gatewayHost = "127.0.0.1:5001"

// authHeader is the authorization header of your BloxRoute Account
const authHeader = "<YOUR-AUTHORIZATION-HEADER>"

func main() {
	// this will use localhost CA to verify the certificate
	creds := credentials.NewClientTLSFromCert(nil, "")

	// Dial the gateway
	conn, err := grpc.Dial(gatewayHost,
		grpc.WithTransportCredentials(creds),
		grpc.WithPerRPCCredentials(blxrCredentials{authorization: authHeader}))

	if err != nil {
		log.Fatalln("dial grpc", err)
	}

	// Create a client
	client := pb.NewGatewayClient(conn)

	// Generate the quote
	quote := genQuote(dAppAddr)

	// Submit the quote
	resp, err := client.SubmitQuote(context.Background(), quote)
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Printf("done submitting the quote to %s\nsolver address: %s\nquote id: %s\n", gatewayHost, quote.SolverAddress, resp.QuoteId)
}

func genQuote(dAppAddr string) *pb.SubmitQuoteRequest{
	// The sample private key of the solver
	solverPrivateKeyHex := "2b36f5c0317c13e6326e9d2e2ae39badec9d030ba44bc889318e4fa5412ad342"

	// The quote is to be submitted as a byte slice.
	// This is a sample quote, and you should replace it with your quote.
	quoteBytes := []byte(`test_quote`)

	// Decode the hex string to a byte slice
	solverPrivateKeyBytes, err := hex.DecodeString(solverPrivateKeyHex)
	if err != nil {
		log.Fatalf("invalid hex string: %v", err)
	}

	// Use the Ethereum crypto package to create an ECDSA private key
	solverPrivateKey, err := crypto.ToECDSA(solverPrivateKeyBytes)
	if err != nil {
		log.Fatalf("failed to create private key: %v", err)
	}

	// Sign the quote with the private key
	quoteHash := crypto.Keccak256Hash(quoteBytes).Bytes()     // need a hash to sign, so we're hashing the payload here
	quoteSig, err := crypto.Sign(quoteHash, solverPrivateKey) // signing the quote
	if err != nil {
		log.Fatalln("could not sign the message", err)
	}

	// Extract the address of the solver
	solverAddress := crypto.PubkeyToAddress(solverPrivateKey.PublicKey).String()

	// Return the quote request
	return &pb.SubmitQuoteRequest{
		DappAddress: dAppAddr,
		SolverAddress:  solverAddress,
		Quote: quoteHash,
		Hash:           quoteHash,
		Signature:      quoteSig,
	}
}

// blxrCredentials is a struct that implements the PerRPCCredentials interface
type blxrCredentials struct {
	authorization string
}

// GetRequestMetadata is a method of the PerRPCCredentials interface
func (bc blxrCredentials) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
	return map[string]string{
		"authorization": bc.authorization,
	}, nil
}

// RequireTransportSecurity is a method of the PerRPCCredentials interface
func (bc blxrCredentials) RequireTransportSecurity() bool {
	return false
}
package main

import (
	"encoding/hex"
	"encoding/json"
	"fmt"
	"log"
	"net/http"

	"github.com/ethereum/go-ethereum/crypto"
	"github.com/gorilla/websocket"
)

// dAppAddr is the dApp addr of the quote
const dAppAddr = "<addr>"

func main() {
	dialer := websocket.DefaultDialer
	// Add the following lines if you work with IP instead of DNS
	// tlsConfig := &tls.Config{
	// 	Certificates:       []tls.Certificate{cert},
	// 	InsecureSkipVerify: true,
	// }
	// dialer.TLSClientConfig = tlsConfig

	req := genquote(dAppAddr)

	wsSubscriber, _, err := dialer.Dial("wss://virginia.eth.blxrbdn.com/ws", http.Header{"Authorization": []string{"YOUR-AUTHORIZATION-HEADER"}})
	if err != nil {
		fmt.Println(err)
		return
	}

	err = wsSubscriber.WriteMessage(websocket.TextMessage, req)
	if err != nil {
		fmt.Println(err)
		return
	}

	for {
		_, nextNotification, err := wsSubscriber.ReadMessage()
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(string(nextNotification)) // or process it generally
	}
}

func genquote(dAppAddr string) []byte {
	// The quote is to be submitted as a byte slice.
	// This is a sample quote, and you should replace it with your quote.
	quote := []byte(`test_quote`)

	// The sample private key of the solver
	solverPrivateKeyHex := "2b36f5c0317c13e6326e9d2e2ae39badec9d030ba44bc889318e4fa5412ad342"

	// Decode the hex string to a byte slice
	solverPrivateKeyBytes, err := hex.DecodeString(solverPrivateKeyHex)
	if err != nil {
		log.Fatalf("invalid hex string: %v", err)
	}

	// Use the Ethereum crypto package to create an ECDSA private key
	solverPrivateKey, err := crypto.ToECDSA(solverPrivateKeyBytes)
	if err != nil {
		log.Fatalf("failed to create private key: %v", err)
	}

	// Sign the quote with the private key
	quotenHash := crypto.Keccak256Hash(quoteBytes).Bytes()     // need a hash to sign, so we're hashing the payload here
	quoteSig, err := crypto.Sign(quotenHash, solverPrivateKey) // signing the hash
	if err != nil {
		log.Fatalln("could not sign the message", err)
	}

	// Extract the address of the solver
	solverAddress := crypto.PubkeyToAddress(solverPrivateKey.PublicKey).String()

	m := map[string]interface{}{
		"solver_address":   solverAddress,
		"dapp_address":     dAppAddr,
		"quote":            quote,
		"hash":             quotenHash,
		"signature":        quoteSig,
	}

	req, err := json.Marshal(m)
	if err != nil {
		log.Fatalln("marshal", err)
	}

	return []byte(fmt.Sprintf(`{"id": "1", "method": "blxr_submit_quote", "params": %s}`, req))
}