Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: example #7

Merged
merged 2 commits into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ func main() {

fmt.Println("latest block number: ", latestBlock.Number(), "nonce: ", nonce)

// bundle price
/*
Unlike sorting in the tx pool based on tx gas prices, the acceptance of a bundle is determined by its overall gas price,
not the gas price of a single transaction. If the overall bundle price is too low, it will be rejected by the network.
The rules for calculating the bundle price are as follows:
bundlePrice = sum(gasFee of each transaction) / sum(gas used of each transaction)
Developers should ensure that the bundlePrice always exceeds the value returned by the eth_bundlePrice API endpoint.
*/
bundlePrice, err := bundleCli.BundlePrice(context.Background())
if err != nil {
panic(err)
}
fmt.Println("bundle price: ", bundlePrice)

if bundlePrice == nil {
// set default
bundlePrice = big.NewInt(5e9)
}

bundle := types.SendBundleArgs{
Txs: make([]hexutil.Bytes, 0),
MaxBlockNumber: 0,
Expand All @@ -67,7 +86,7 @@ func main() {
To: &address,
Value: big.NewInt(params.GWei),
Gas: uint64(5000000),
GasPrice: big.NewInt(5e9),
GasPrice: bundlePrice,
Data: nil,
}

Expand Down Expand Up @@ -100,13 +119,6 @@ func main() {
bundleJson, _ := jsoniter.Marshal(bundleQuery)
fmt.Println("bundle queried: ", string(bundleJson))

// bundle price
bundlePrice, err := bundleCli.BundlePrice(context.Background())
if err != nil {
panic(err)
}
fmt.Println("bundle price: ", bundlePrice)

// builders
builders, err := bundleCli.Builders(context.Background())
if err != nil {
Expand Down
Loading