You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/guide.rst
+122-3Lines changed: 122 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,15 +116,15 @@ There is a number of useful hooks that you can use to read blockchain state:
116
116
117
117
- ``useBlockMeta()`` - return meta information (``timestamp`` and ``difficulty``) about most recent block mined
118
118
- ``useEtherBalance(address)`` - returns ether balance as BigNumber for given address (or ``undefined``)
119
-
- ``useTokenBalance(tokenAddress, address)``- returns balance of a given token as BigNumber for given address (or undefined)
119
+
- ``useTokenBalance(tokenAddress, address)``- returns balance of a given token as BigNumber for given address (or undefined)
120
120
- ``useTokenAllowance(tokenAddress, ownerAddress, spenderAddress)`` - returns allowance of a given token as BigNumber for given owner and spender address pair (or undefined)
121
121
122
122
Sooner or later you will want to make a custom call to a smart contract. Use ``useContractCall`` and ``useContractCalls`` for that purpose.
123
123
See section below on creating custom hooks.
124
124
125
125
126
126
Custom hooks
127
-
************
127
+
============
128
128
129
129
Creating a custom hook with the use of our core hooks is straightforward, for example let’s examine the *useTokenBalance* hook.
130
130
@@ -189,7 +189,7 @@ If that is too complex consider using a custom backend or `The Graph <https://th
189
189
190
190
191
191
Testing hooks
192
-
*************
192
+
=============
193
193
194
194
Let's take ``useTokenAllowance`` as an example.
195
195
@@ -281,3 +281,122 @@ Then we can check if our result is correct. ``result.current`` is a value return
281
281
})
282
282
283
283
284
+
Transactions
285
+
************
286
+
287
+
Sending
288
+
=======
289
+
290
+
To send transations use ``useContractFunction``hook. Hook returns an object with two variables:``state`` and ``send``.
291
+
292
+
The former represents the state oftransaction. Transaction state always contains ``status``, which can be one of the following:
293
+
294
+
-**None**- before a transaction is created.
295
+
-**Mining**- when a transaction is sent to the network, but not yet mined. Inthis state ``transaction: TransactionResponse`` is available.
296
+
-**Success**- when a transaction has been mined successfully. Inthis state ``transaction: TransactionResponse`` and ``receipt: TransactionReceipt`` are available.
297
+
-**Failed**- when a transaction has been mined, but ended up reverted. Again``transaction: TransactionResponse`` and ``receipt: TransactionReceipt`` are available.
298
+
-**Exception**- when a transaction hasn't started, due to the exception that was thrown before the transaction was propagated to the network. The exception can come from application/library code (e.g. unexpected exception like malformed arguments) or externally (e.g user discarded transaction in Metamask). In this state the ``errorMessage: string`` is available (as well as exception object).
299
+
300
+
Additionally all states except ``None``, contain ``chainId: ChainId``.
301
+
302
+
To send a transaction use ``send`` function returned by ``useContractFunction``.
303
+
The function forwards arguments to ethers.js contract object, so that arguments map 1 to 1 with Solidity function arguments.
304
+
Additionally, there can be one extra argument - `TransactionOverrides <https://docs.ethers.io/v5/api/contract/contract/#Contract-functionsCall>`_, which can be used to manipulate transaction parameters like gasPrice, nonce, etc
The code snippets above will wrap and unwrap Ether into WETH using Wrapped Ether `contract <https://etherscan.io/address/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2#code>`_ respectively.
324
+
325
+
326
+
History
327
+
=======
328
+
329
+
To access list of user's transactions (with all statuses) use ``useTransactions`` hook.
330
+
Transactions are stored in local storage and the status is rechecked on every newblock.
331
+
332
+
Take a look at example usage below:
333
+
334
+
.. code-block:: javascript
335
+
336
+
const { transactions } =useTransactions()
337
+
338
+
339
+
Transaction has following type:
340
+
341
+
.. code-block:: javascript
342
+
343
+
exportinterfaceStoredTransaction {
344
+
transaction: TransactionResponse
345
+
submittedAt: number
346
+
receipt?: TransactionReceipt
347
+
lastCheckedBlockNumber?: number
348
+
transactionName?: string
349
+
}
350
+
351
+
352
+
353
+
Notifications
354
+
=============
355
+
356
+
Additonally, you can access notifications via ``useNotifications`` hook.
357
+
Notifications include information about:newtransactions, transaction success or failure, as well as connection to a newwallet.
358
+
359
+
Take a look at example usage below:
360
+
361
+
.. code-block:: javascript
362
+
363
+
const { notifications } =useNotifications()
364
+
365
+
366
+
``notifications`` are arrays of``NotificationPayload``. Each can be one of the following:
0 commit comments