Skip to content

Commit 337c93b

Browse files
authored
fix: readme & example (#13)
1 parent 11b7552 commit 337c93b

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

.changeset/nice-lies-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@node-real/web3-plugin-bundle": minor
3+
---
4+
5+
fix readme & example

README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ web3 = new Web3(/* provider here */);
3535
web3.registerPlugin(new Web3BundlePlugin());
3636
```
3737

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`
3945

4046
```typescript
4147
import * as process from "process";
@@ -58,13 +64,34 @@ const address: Address = process.env.Address as Address;
5864
const nonce = await web3.eth.getTransactionCount(address, "latest");
5965
const txs: string[] = [];
6066

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+
6188
for (let i = 0; i < 3; i++) {
6289
const tx: Transaction = {
6390
from: address,
6491
to: address,
6592
value: web3.utils.toWei(0.0001, "ether"),
6693
gas: 0x17530,
67-
gasPrice: 0x12a05f200,
94+
gasPrice: bundlePrice,
6895
nonce: nonce + BigInt(i),
6996
};
7097
// sign your tx
@@ -95,13 +122,6 @@ const bundleObj = await web3.bundle
95122
console.error(reason);
96123
});
97124

98-
// query bundlePrice
99-
const bundlePrice = await web3.bundle
100-
.bundlePrice()
101-
.catch((reason: any) => {
102-
console.error(reason);
103-
});
104-
105125
// query builders
106126
const builders = await web3.bundle
107127
.builders()

test/index.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,34 @@ describe("Web3BundlePlugin Tests", () => {
4242

4343
const txs: string[] = [];
4444

45+
// bundle price
46+
/*
47+
Unlike sorting in the tx pool based on tx gas prices, the acceptance of a bundle is determined by its overall gas price,
48+
not the gas price of a single transaction. If the overall bundle price is too low, it will be rejected by the network.
49+
The rules for calculating the bundle price are as follows:
50+
bundlePrice = sum(gasFee of each transaction) / sum(gas used of each transaction)
51+
Developers should ensure that the bundlePrice always exceeds the value returned by the eth_bundlePrice API endpoint.
52+
*/
53+
let bundlePrice = await web3.bundle
54+
.bundlePrice()
55+
.catch((reason: any) => {
56+
console.error(reason);
57+
fail();
58+
});
59+
console.info("bundlePrice", bundlePrice);
60+
61+
if (bundlePrice == null) {
62+
// set default
63+
bundlePrice = BigInt(5e9)
64+
}
65+
4566
for (let i = 0; i < 3; i++) {
4667
const tx: Transaction = {
4768
from: address,
4869
to: address,
4970
value: web3.utils.toWei(0.0001, "ether"),
5071
gas: 0x17530,
51-
gasPrice: 0x12a05f200,
72+
gasPrice: bundlePrice,
5273
nonce: nonce + BigInt(i),
5374
};
5475
const signedTx = await web3.eth.accounts

0 commit comments

Comments
 (0)