Skip to content

Commit 3a97be9

Browse files
committed
add watchContractEvent
1 parent d5f9b83 commit 3a97be9

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Simple WalletConnect v2 integration package for Vue3 apps.
2323
- [FetchToken](#fetchtoken)
2424
- [ReadContract](#readcontract)
2525
- [WriteContract](#writecontract)
26+
- [WatchContractEvent](#watchcontractevent)
2627
- [EstimateWriteContractGas](#estimatewritecontractgas)
2728
- [Demo](#demo)
2829
- [Example](#example)
@@ -36,7 +37,6 @@ Simple WalletConnect v2 integration package for Vue3 apps.
3637
# Getting started
3738

3839
## Installation
39-
4040
Use yarn or npm to install the package `@kolirt/vue-web3-auth`.
4141

4242
```bash
@@ -46,7 +46,6 @@ yarn add @kolirt/vue-web3-auth
4646
```
4747

4848
## Setup
49-
5049
Add dependencies to your `main.js`:
5150

5251
```javascript
@@ -231,7 +230,6 @@ let data = await fetchToken({
231230
```
232231

233232
## ReadContract
234-
235233
```ts
236234
import {erc20ABI, readContract} from '@kolirt/vue-web3-auth'
237235

@@ -250,7 +248,6 @@ let data = await readContract({
250248
```
251249

252250
## WriteContract
253-
254251
```ts
255252
import {erc20ABI, writeContract} from '@kolirt/vue-web3-auth'
256253

@@ -262,8 +259,21 @@ let data = await writeContract({
262259
})
263260
```
264261

265-
## EstimateWriteContractGas
262+
## WatchContractEvent
263+
The function works on the basis of pooling, not on the websockets
264+
```js
265+
import {erc20ABI, watchContractEvent} from '@kolirt/vue-web3-auth'
266266

267+
const unwatch = watchContractEvent({
268+
address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
269+
abi: erc20ABI,
270+
eventName: 'Transfer'
271+
}, (log) => {
272+
console.log(log)
273+
})
274+
```
275+
276+
## EstimateWriteContractGas
267277
```ts
268278
import {erc20ABI, estimateWriteContractGas} from '@kolirt/vue-web3-auth'
269279

lib/actions/event.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type {WatchContractEvent} from '../types'
2+
import {watchContractEvent as masterWatchContractEvent} from '@wagmi/core'
3+
import {chain} from '../chain'
4+
5+
export function watchContractEvent(data: WatchContractEvent, callback: (log: any) => void) {
6+
return masterWatchContractEvent({
7+
chainId: data?.chainId || chain.value.id,
8+
address: data.address,
9+
abi: data.abi,
10+
eventName: data.eventName
11+
}, callback)
12+
}

lib/actions/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export {
1212
estimateWriteContractGas
1313
} from './contract'
1414

15+
export {
16+
watchContractEvent
17+
} from './event'
18+
1519
export {
1620
fetchGasPrice
1721
} from './gas'

lib/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ export type WriteContract = {
8585
confirmations?: number
8686
}
8787

88+
export type WatchContractEvent = {
89+
chainId?: number
90+
address: `0x${string}` | `0x${string}`[]
91+
abi: any
92+
eventName: string
93+
}
94+
8895
export type FetchBalance = {
8996
chainId?: number
9097
address: `0x${string}`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kolirt/vue-web3-auth",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "Web3 authentication for Vue3 apps based on WalletConnect v2",
55
"author": "kolirt",
66
"license": "MIT",

0 commit comments

Comments
 (0)