Skip to content

Commit 55772c4

Browse files
authored
Add chequebook management page (#232)
* add chequebook management page * wording
1 parent 096c7c9 commit 55772c4

File tree

1 file changed

+131
-7
lines changed

1 file changed

+131
-7
lines changed

docs/documentation/chequebook.md

Lines changed: 131 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,136 @@
11
---
2-
title: Chequebook and Cheques
2+
title: Chequebook Management
33
id: chequebook
44
slug: /chequebook
5-
sidebar_label: Chequebook and Cheques
5+
sidebar_label: Chequebook Management
66
---
77

8-
* Get chequebook balance
9-
* Withdraw from chequebook to node wallet
10-
* Deposit to chequebook from node wallet
11-
* Get cheques
12-
* Cashout cheque
8+
On Swarm, when downloading data from the network, nodes pay each other for forwarding data in the form of cheques. If you will be downloading a significant amount of data from the network, it is important that you fund your chequebook with BZZ so your node can issue and then pay for cheques.
9+
10+
You can also fund your chequebook by running a full node and getting paid in BZZ for forwarding chunks to other nodes, however this may not be enough depending on your download volume.
11+
12+
:::tip
13+
If using your node for downloads, it's recommended to actively monitor your node's chequebook balance and top it up once the balance begins to run low.
14+
:::
15+
16+
### Requirements
17+
18+
To use the example scripts below, you need:
19+
20+
- An instance of `bee-js`'s `Bee` [initialized](/docs/getting-started/) using the API endpoint of a currently operating ***FULL*** Bee node.
21+
- Some BZZ to fund your chequebook.
22+
23+
### 1. Deposit to Chequebook from Node Wallet
24+
25+
Deposits a specified amount of BZZ into the chequebook from your node wallet. This ensures that your node can issue cheques for transactions.
26+
27+
```javascript
28+
const amount = new BZZ.fromDecimalString('1') // Deposit 1 BZZ
29+
30+
const transactionHash = await bee.depositTokens(amount)
31+
console.log('Deposit transaction hash:', transactionHash.toHex())
32+
```
33+
34+
```bash
35+
Deposit transaction hash: 85362b9d3ed2ba520b12e4e6523546832064365621ece8b3881cd1dfd40365ec
36+
```
37+
38+
### 2. Get Chequebook Balance
39+
40+
Retrieves the current balance of the chequebook. This helps you ensure that you have enough BZZ to continue issuing cheques.
41+
42+
```javascript
43+
const chequebookBalance = await bee.getChequebookBalance()
44+
console.log('Chequebook Balance:', chequebookBalance)
45+
```
46+
47+
```bash
48+
Chequebook Balance: {
49+
availableBalance: BZZ { state: FixedPointNumber { value: 10000000000000000n, scale: 16 } },
50+
totalBalance: BZZ { state: FixedPointNumber { value: 10000000000000000n, scale: 16 } }
51+
}
52+
```
53+
54+
### 3. Withdraw from Chequebook to Node Wallet
55+
56+
Withdraws a specified amount of BZZ from the chequebook to the node wallet. You may need to withdraw if you want to transfer BZZ to another account or for other uses.
57+
58+
```javascript
59+
const amountToWithdraw = new BZZ.fromDecimalString('1') // Withdraw 1 BZZ
60+
61+
const withdrawalHash = await bee.withdrawTokens(amountToWithdraw)
62+
console.log('Withdraw transaction hash:', withdrawalHash.toHex())
63+
```
64+
65+
```bash
66+
Withdraw transaction hash: 7674b1070406f60c317d26d5155521d674e5494db8f90cabbf46de0e22fc5556
67+
```
68+
69+
### 4. Get Cheques
70+
71+
Retrieves information about the last sent and received cheques from peers, either for all peers or for a specific peer.
72+
73+
#### Get Last Cheques for All Peers
74+
75+
This method retrieves the most recent cheques sent or received for all peers. Each entry includes details like the recipient, chequebook address, and payout amount.
76+
77+
```javascript
78+
const lastCheques = await bee.getLastCheques()
79+
console.log('Last Cheques for all peers:', lastCheques)
80+
```
81+
82+
```bash
83+
Last Cheques for all peers: {
84+
lastcheques: [
85+
{
86+
peer: '10f68a7f7fe8b85e04ae0c869c02852f1b568b145c7f59179feef0601d9f1bf7',
87+
lastreceived: null,
88+
lastsent: {
89+
beneficiary: [EthAddress],
90+
chequebook: [EthAddress],
91+
payout: [BZZ]
92+
}
93+
},
94+
...
95+
]
96+
}
97+
```
98+
99+
#### Get Cheques for a Specific Peer
100+
101+
Fetches the last cheques for a particular peer. This can help you track your cheques for specific interactions.
102+
103+
```javascript
104+
const peerAddress = '10f68a7f7fe8b85e04ae0c869c02852f1b568b145c7f59179feef0601d9f1bf7'
105+
const lastChequesForPeer = await bee.getLastChequesForPeer(peerAddress)
106+
console.log(`Last cheques for peer ${peerAddress}:`, lastChequesForPeer)
107+
```
108+
109+
```bash
110+
Last cheques for peer 10f68a7f7fe8b85e04ae0c869c02852f1b568b145c7f59179feef0601d9f1bf7: {
111+
peer: '10f68a7f7fe8b85e04ae0c869c02852f1b568b145c7f59179feef0601d9f1bf7',
112+
lastreceived: null,
113+
lastsent: {
114+
beneficiary: EthAddress { bytes: [Uint8Array], length: 20 },
115+
chequebook: EthAddress { bytes: [Uint8Array], length: 20 },
116+
payout: BZZ { state: [FixedPointNumber] }
117+
}
118+
}
119+
```
120+
121+
### 5. Cash-out Cheque
122+
123+
Cash out a cheque for a specific peer. This method allows you to retrieve funds from a cheque that has been issued to you by a peer.
124+
125+
#### Cashout the Last Cheque
126+
127+
```javascript
128+
const peerAddress = '10f68a7f7fe8b85e04ae0c869c02852f1b568b145c7f59179feef0601d9f1bf7'
129+
130+
const transactionId = await bee.cashoutLastCheque(peerAddress)
131+
console.log('Cashout transaction ID:', transactionId)
132+
```
133+
134+
```bash
135+
Cashout transaction ID: dabb1d1b129d4c6317b96db23d9ca2d417aec9961f9a4d52f6b24e165b525eb8
136+
```

0 commit comments

Comments
 (0)