@@ -35,7 +35,13 @@ web3 = new Web3(/* provider here */);
35
35
web3 .registerPlugin (new Web3BundlePlugin ());
36
36
```
37
37
38
- ### Methods
38
+ ### Example
39
+
40
+ Developer can run example by these steps:
41
+ 1 . set env APIKEY ([ your meganode apikey] ( https://nodereal.io/api-marketplace/bsc-bundle-service-api ) )
42
+ 2 . set env PrivateKey (sign transactions)
43
+ 3 . set env Address (to address of transactions)
44
+ 4 . ` pnpm run test `
39
45
40
46
``` typescript
41
47
import * as process from " process" ;
@@ -58,13 +64,34 @@ const address: Address = process.env.Address as Address;
58
64
const nonce = await web3 .eth .getTransactionCount (address , " latest" );
59
65
const txs: string [] = [];
60
66
67
+ // bundle price
68
+ /*
69
+ Unlike sorting in the tx pool based on tx gas prices, the acceptance of a bundle is determined by its overall gas price,
70
+ not the gas price of a single transaction. If the overall bundle price is too low, it will be rejected by the network.
71
+ The rules for calculating the bundle price are as follows:
72
+ bundlePrice = sum(gasFee of each transaction) / sum(gas used of each transaction)
73
+ Developers should ensure that the bundlePrice always exceeds the value returned by the eth_bundlePrice API endpoint.
74
+ */
75
+ let bundlePrice = await web3 .bundle
76
+ .bundlePrice ()
77
+ .catch ((reason : any ) => {
78
+ console .error (reason );
79
+ fail ();
80
+ });
81
+ console .info (" bundlePrice" , bundlePrice );
82
+
83
+ if (bundlePrice == null ) {
84
+ // set default
85
+ bundlePrice = BigInt (5e9 )
86
+ }
87
+
61
88
for (let i = 0 ; i < 3 ; i ++ ) {
62
89
const tx: Transaction = {
63
90
from: address ,
64
91
to: address ,
65
92
value: web3 .utils .toWei (0.0001 , " ether" ),
66
93
gas: 0x17530 ,
67
- gasPrice: 0x12a05f200 ,
94
+ gasPrice: bundlePrice ,
68
95
nonce: nonce + BigInt (i ),
69
96
};
70
97
// sign your tx
@@ -95,13 +122,6 @@ const bundleObj = await web3.bundle
95
122
console .error (reason );
96
123
});
97
124
98
- // query bundlePrice
99
- const bundlePrice = await web3 .bundle
100
- .bundlePrice ()
101
- .catch ((reason : any ) => {
102
- console .error (reason );
103
- });
104
-
105
125
// query builders
106
126
const builders = await web3 .bundle
107
127
.builders ()
0 commit comments