Skip to content

Commit 35c2871

Browse files
authored
fix: example (#7)
1 parent f95878a commit 35c2871

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

example/example.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ func main() {
5454

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

57+
// bundle price
58+
/*
59+
Unlike sorting in the tx pool based on tx gas prices, the acceptance of a bundle is determined by its overall gas price,
60+
not the gas price of a single transaction. If the overall bundle price is too low, it will be rejected by the network.
61+
The rules for calculating the bundle price are as follows:
62+
bundlePrice = sum(gasFee of each transaction) / sum(gas used of each transaction)
63+
Developers should ensure that the bundlePrice always exceeds the value returned by the eth_bundlePrice API endpoint.
64+
*/
65+
bundlePrice, err := bundleCli.BundlePrice(context.Background())
66+
if err != nil {
67+
panic(err)
68+
}
69+
fmt.Println("bundle price: ", bundlePrice)
70+
71+
if bundlePrice == nil {
72+
// set default
73+
bundlePrice = big.NewInt(5e9)
74+
}
75+
5776
bundle := types.SendBundleArgs{
5877
Txs: make([]hexutil.Bytes, 0),
5978
MaxBlockNumber: 0,
@@ -67,7 +86,7 @@ func main() {
6786
To: &address,
6887
Value: big.NewInt(params.GWei),
6988
Gas: uint64(5000000),
70-
GasPrice: big.NewInt(5e9),
89+
GasPrice: bundlePrice,
7190
Data: nil,
7291
}
7392

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

103-
// bundle price
104-
bundlePrice, err := bundleCli.BundlePrice(context.Background())
105-
if err != nil {
106-
panic(err)
107-
}
108-
fmt.Println("bundle price: ", bundlePrice)
109-
110122
// builders
111123
builders, err := bundleCli.Builders(context.Background())
112124
if err != nil {

0 commit comments

Comments
 (0)