Giter Site home page Giter Site logo

bundlerpc's Introduction

Flashbots Bundle RPC

Go Reference Go Report Card

BundleRPC implements Flashbots JSON-RPC client that is compatible with the standard Go-Ethereum data types.

For more information about Flashbots RPC, please visit their documentation website.

Quick Start by Example

The following code snippet is incomplete and cannot be run as-is. However, it can be used as the starting point for interacting with the Flashbots RPC.

package main

import (
    "fmt"

    "github.com/adzil/bundlerpc"
    "github.com/ethereum/go-ethereum/core/types"
    "github.com/ethereum/go-ethereum/crypto"
    "github.com/ethereum/go-ethereum/ethclient"
    "github.com/ethereum/go-ethereum/rpc"
)

func main() {
    // Create random private key for signing the Flashbots JSON-RPC payload.
    // Consider using stored private key for long-term usage to build
    // reputation with the Flashbots relay.
    flashbotsKey, err := crypto.GenerateKey()
    if err != nil {
        panic(err)
    }

    // Create new JSON-RPC client using the previously generated private key.
    flashbots, err := bundlerpc.Dial("https://relay.flashbots.net", flashbotsKey)
    if err != nil {
        panic(err)
    }

    // Instantiate the Eth client to obtain the latest block number.
    ethrpc, err := rpc.Dial("http://localhost:8545")
    if err != nil {
        panic(err)
    }
    defer ethrpc.Close()
    eth := ethclient.NewClient(ethrpc)

    // ...Build the actual transactions here...
    var txOne, txTwo *types.Transaction

    // Get the latest block number.
    blockNumber, err := eth.BlockNumber(context.Background())
    if err != nil {
        panic(err)
    }

    // Send transaction bundle of txOne and txTwo using Flashbots relay. Note
    // that you must explicitly set NoSend field in the bind.TransactionOpts to
    // prevent sending them into the public mempool.
    bundle, err := flashbots.SendBundle(context.Background(), bundlerpc.SendBundleParam{
        Txs: []*types.Transaction{
            txOne,
            txTwo,
        },
        BlockNumber: blockNumber,
    })
    if err != nil {
        panic(err)
    }

    // Print the resulting bundle hash.
    fmt.Printf("%#v\n", bundle)
}

bundlerpc's People

Contributors

adzil avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.