0

I have using golang to write a flashbot sendBundle method:

func SendBundle(rpc string, rawTx string, blockNum *big.Int, pk string) {
    fmt.Println("sending tx", rpc)
    blockDelay := viper.GetInt64("private_buy.block_delay")
    if blockDelay == 0 {
        log.Fatalln("block_delay cannot 0")
    }
    //blockNum + blockDelay
    blockNum = blockNum.Add(blockNum, big.NewInt(blockDelay))

    //blockNum to hex
    blockNumHex := fmt.Sprintf("0x%x", blockNum)

    sendBundleArgs := flashbotsrpc.FlashbotsSendBundleRequest{
        Txs:         []string{"0x" + rawTx},
        BlockNumber: blockNumHex,
    }

    // https://github.com/metachris/flashbotsrpc
    rpcNode := flashbotsrpc.New(rpc)
    privateKey, err := crypto.HexToECDSA(pk)
    if err != nil {
        log.Fatal("Failed to parse private key", err)
    }
    result, err := rpcNode.FlashbotsSendBundle(privateKey, sendBundleArgs)
    if err != nil {
        panic(err)
    }
    fmt.Printf("%+v\n", result)
}

I have encode uniswap tx with following:

//uniswapV2Router is a Go Contract Binding
tx, err = uniswapv2Router.SwapExactETHForTokens(txOpts, amountOutMin, path, publicKeyAddress, big.NewInt(now))

txBytes := &bytes.Buffer{}

err = tx.EncodeRLP(txBytes)
if err != nil {
    panic(err)
}

rawTx := hex.EncodeToString(txBytes.Bytes())

but error:

{"error":"unable to decode txs"}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.