11<h1 align =" center " >Web3 authentication for Vue3 apps based on WalletConnect v2 and wagmi</h1 >
22
3- <p style = " display : flex ; align-content : center ; justify-content : center ; " >
3+ <p align = " center " >
44 <img src =" https://img.shields.io/static/v1?label=Made%20with&message=VueJS&color=limegreen&style=for-the-badge&logo=vue.js " />
55 <img src =" https://img.shields.io/badge/Made%20for-Dapps-orange?style=for-the-badge&logo=ethereum " />
66</p >
77
88Simple WalletConnect v2 integration package for Vue3 apps.
99
1010** Table of Contents**
11+
1112- [ Getting started] ( #getting-started )
1213 - [ Installation] ( #installation )
1314 - [ Setup] ( #setup )
1415- [ Usage] ( #usage )
15- - [ Connect wallet button] ( #connect-wallet-button )
16- - [ FetchGasPrice] ( #fetchgasprice )
17- - [ FetchBlockNumber] ( #fetchblocknumber )
18- - [ FetchTransaction] ( #fetchtransaction )
19- - [ SendTransaction] ( #sendtransaction )
20- - [ SignMessage] ( #signmessage )
21- - [ Multicall] ( #multicall )
22- - [ FetchBalance] ( #fetchbalance )
23- - [ FetchToken] ( #fetchtoken )
24- - [ ReadContract] ( #readcontract )
25- - [ WriteContract] ( #writecontract )
26- - [ WatchContractEvent] ( #watchcontractevent )
27- - [ EstimateWriteContractGas] ( #estimatewritecontractgas )
16+ - [ Basic usage] ( #basic-usage )
17+ - [ Connect wallet button] ( #connect-wallet-button )
18+ - [ FetchGasPrice] ( #fetchgasprice )
19+ - [ FetchBlockNumber] ( #fetchblocknumber )
20+ - [ FetchTransaction] ( #fetchtransaction )
21+ - [ SendTransaction] ( #sendtransaction )
22+ - [ SignMessage] ( #signmessage )
23+ - [ Multicall] ( #multicall )
24+ - [ FetchBalance] ( #fetchbalance )
25+ - [ FetchToken] ( #fetchtoken )
26+ - [ ReadContract] ( #readcontract )
27+ - [ WriteContract] ( #writecontract )
28+ - [ WatchContractEvent] ( #watchcontractevent )
29+ - [ EstimateWriteContractGas] ( #estimatewritecontractgas )
30+ - [ Composable] ( #composable )
31+ - [ UseFetchBalance] ( #usefetchbalance )
2832- [ Demo] ( #demo )
2933- [ Example] ( #example )
3034- [ Faq] ( #faq )
@@ -37,6 +41,7 @@ Simple WalletConnect v2 integration package for Vue3 apps.
3741# Getting started
3842
3943## Installation
44+
4045Use yarn or npm to install the package ` @kolirt/vue-web3-auth ` .
4146
4247``` bash
@@ -46,6 +51,7 @@ yarn add @kolirt/vue-web3-auth
4651```
4752
4853## Setup
54+
4955Add dependencies to your ` main.js ` :
5056
5157``` javascript
@@ -55,20 +61,25 @@ import {Chains, createWeb3Auth} from '@kolirt/vue-web3-auth'
5561const app = createApp ({... })
5662
5763app .use (createWeb3Auth ({
58- projectId: ' ' , // generate here https://cloud.walletconnect.com/ and turn on 'Supports Sign v2'
59- chains: [
60- Chains .bsc ,
61- Chains .mainnet ,
62- Chains .polygon
63- ]
64+ projectId: ' ' , // generate here https://cloud.walletconnect.com/ and turn on 'Supports Sign v2'
65+ chains: [
66+ Chains .bsc ,
67+ Chains .mainnet ,
68+ Chains .polygon
69+ ]
6470}))
6571
6672app .mount (' #app' )
6773```
6874
6975# Usage
70- ## Connect wallet button
76+
77+ ## Basic usage
78+
79+ ### Connect wallet button
80+
7181``` vue
82+
7283<script setup lang="ts">
7384import {account, disconnect, connect} from '@kolirt/vue-web3-auth'
7485</script>
@@ -83,7 +94,8 @@ import {account, disconnect, connect} from '@kolirt/vue-web3-auth'
8394</template>
8495```
8596
86- ## FetchGasPrice
97+ ### FetchGasPrice
98+
8799``` js
88100import {fetchGasPrice } from ' @kolirt/vue-web3-auth'
89101
@@ -101,7 +113,8 @@ let data = await fetchGasPrice()
101113 */
102114```
103115
104- ## FetchBlockNumber
116+ ### FetchBlockNumber
117+
105118``` js
106119import {fetchBlockNumber } from ' @kolirt/vue-web3-auth'
107120
@@ -114,53 +127,57 @@ let data = await fetchBlockNumber()
114127 */
115128```
116129
117- ## FetchTransaction
130+ ### FetchTransaction
131+
118132``` js
119133import {fetchTransaction } from ' @kolirt/vue-web3-auth'
120134
121135let txn = await fetchTransaction ({
122- hash: ' 0x7ed8dc64f54ae43f4d53173e95aa929c52de44ec5cea8c28246989914ed7f4fb'
136+ hash: ' 0x7ed8dc64f54ae43f4d53173e95aa929c52de44ec5cea8c28246989914ed7f4fb'
123137})
124138```
125139
126- ## SendTransaction
140+ ### SendTransaction
141+
127142``` js
128143import {sendTransaction } from ' @kolirt/vue-web3-auth'
129144
130145let txn = await sendTransaction ({
131- to: ' 0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9' ,
132- value: 1n
146+ to: ' 0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9' ,
147+ value: 1n
133148})
134149```
135150
136- ## SignMessage
151+ ### SignMessage
152+
137153``` js
138154import {signMessage } from ' @kolirt/vue-web3-auth'
139155
140156const signature = await signMessage (' test message' )
141157```
142158
143- ## Multicall
159+ ### Multicall
160+
144161``` ts
145162import {multicallABI , multicall , chain } from ' @kolirt/vue-web3-auth'
146163
147164let data = await multicall ({
148- calls: [
149- {
150- abi: multicallABI ,
151- contractAddress: chain .value .contracts .multicall3 .address ,
152- calls: [
153- [' getEthBalance' , [' 0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9' ]],
154- [' getEthBalance' , [' 0x295e26495CEF6F69dFA69911d9D8e4F3bBadB89B' ]],
155- [' getEthBalance' , [' 0x2465176C461AfB316ebc773C61fAEe85A6515DAA' ]]
156- ]
157- }
158- ]
165+ calls: [
166+ {
167+ abi: multicallABI ,
168+ contractAddress: chain .value .contracts .multicall3 .address ,
169+ calls: [
170+ [' getEthBalance' , [' 0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9' ]],
171+ [' getEthBalance' , [' 0x295e26495CEF6F69dFA69911d9D8e4F3bBadB89B' ]],
172+ [' getEthBalance' , [' 0x2465176C461AfB316ebc773C61fAEe85A6515DAA' ]]
173+ ]
174+ }
175+ ]
159176})
160177
161178/**
162179 * Result in data
163- *
180+ *
164181 * [
165182 * {result: 1908669631824871303n, status: "success"},
166183 * {result: 133515691552422277n, status: "success"},
@@ -169,12 +186,13 @@ let data = await multicall({
169186 */
170187```
171188
172- ## FetchBalance
189+ ### FetchBalance
190+
173191``` js
174192import {fetchBalance } from ' @kolirt/vue-web3-auth'
175193
176194let bnbBalance = await fetchBalance ({
177- address: ' 0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9'
195+ address: ' 0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9'
178196})
179197
180198/**
@@ -189,8 +207,8 @@ let bnbBalance = await fetchBalance({
189207 */
190208
191209let tokenBalance = await fetchBalance ({
192- address: ' 0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9' ,
193- token: ' 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'
210+ address: ' 0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9' ,
211+ token: ' 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'
194212})
195213
196214/**
@@ -205,12 +223,13 @@ let tokenBalance = await fetchBalance({
205223 */
206224```
207225
208- ## FetchToken
226+ ### FetchToken
227+
209228``` js
210229import {fetchToken } from ' @kolirt/vue-web3-auth'
211230
212231let data = await fetchToken ({
213- address: ' 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'
232+ address: ' 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'
214233})
215234
216235/**
@@ -229,70 +248,99 @@ let data = await fetchToken({
229248 */
230249```
231250
232- ## ReadContract
251+ ### ReadContract
252+
233253``` ts
234254import {erc20ABI , readContract } from ' @kolirt/vue-web3-auth'
235255
236256let data = await readContract ({
237- address: ' 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c' , // wbnb on bsc
238- abi: erc20ABI ,
239- functionName: ' balanceOf' ,
240- args: [' 0x36696169c63e42cd08ce11f5deebbcebae652050' ]
257+ address: ' 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c' , // wbnb on bsc
258+ abi: erc20ABI ,
259+ functionName: ' balanceOf' ,
260+ args: [' 0x36696169c63e42cd08ce11f5deebbcebae652050' ]
241261})
242262
243263/**
244264 * Result in data
245- *
265+ *
246266 * 107109316688516684525777n
247267 */
248268```
249269
250- ## WriteContract
270+ ### WriteContract
271+
251272``` ts
252273import {erc20ABI , writeContract } from ' @kolirt/vue-web3-auth'
253274
254275let data = await writeContract ({
255- abi: erc20ABI ,
256- address: ' 0x55d398326f99059fF775485246999027B3197955' ,
257- functionName: ' approve' ,
258- args: [' 0x685B1ded8013785d6623CC18D214320b6Bb64759' , 100 ]
276+ abi: erc20ABI ,
277+ address: ' 0x55d398326f99059fF775485246999027B3197955' ,
278+ functionName: ' approve' ,
279+ args: [' 0x685B1ded8013785d6623CC18D214320b6Bb64759' , 100 ]
259280})
260281```
261282
262- ## WatchContractEvent
283+ ### WatchContractEvent
284+
263285The function works on the basis of pooling, not on the websockets
286+
264287``` js
265288import {erc20ABI , watchContractEvent } from ' @kolirt/vue-web3-auth'
266289
267290const unwatch = watchContractEvent ({
268- address: ' 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c' ,
269- abi: erc20ABI,
270- eventName: ' Transfer'
291+ address: ' 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c' ,
292+ abi: erc20ABI,
293+ eventName: ' Transfer'
271294}, (log ) => {
272- console .log (log)
295+ console .log (log)
273296})
274297```
275298
276- ## EstimateWriteContractGas
299+ ### EstimateWriteContractGas
300+
277301``` ts
278302import {erc20ABI , estimateWriteContractGas } from ' @kolirt/vue-web3-auth'
279303
280304const gas = await estimateWriteContractGas ({
281- abi: erc20ABI ,
282- address: ' 0x55d398326f99059fF775485246999027B3197955' ,
283- functionName: ' approve' ,
284- args: [' 0x685B1ded8013785d6623CC18D214320b6Bb64759' , 100 ]
285- }).catch (e => {})
305+ abi: erc20ABI ,
306+ address: ' 0x55d398326f99059fF775485246999027B3197955' ,
307+ functionName: ' approve' ,
308+ args: [' 0x685B1ded8013785d6623CC18D214320b6Bb64759' , 100 ]
309+ }).catch (e => {
310+ })
311+ ```
312+
313+ ## Composable
314+
315+ ### UseFetchBalance
316+ ``` js
317+ import {useFetchBalance } from ' @kolirt/vue-web3-auth'
318+
319+ // use `fetch` for manual init when `disableAutoFetch` is `true`
320+ const {
321+ loaded , fetching , data ,
322+ fetch, reload, disableAutoReload
323+ } = useFetchBalance ({
324+ address: ' 0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9'
325+ }, {
326+ disableAutoFetch: false ,
327+ autoReloadTime: 30000 ,
328+ disableAutoReload: false
329+ })
286330```
287331
288332# Demo
333+
289334[ Demo here] ( https://kolirt.github.io/vue-web3-auth/ ) .
290335
291336# Example
337+
292338[ Example here] ( https://github.com/kolirt/vue-web3-auth/blob/master/src ) .
293339
294340# FAQ
341+
295342Check closed [ issues] ( https://github.com/kolirt/vue-web3-auth/issues ) to get answers for most asked questions.
296343
297344# License
345+
298346[ MIT] ( https://github.com/kolirt/vue-web3-auth/blob/master/LICENSE ) .
0 commit comments