├── .env.development
├── .env.production
├── .eslintignore
├── .eslintrc.cjs
├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── bug-report.yml
│ ├── config.yml
│ ├── feature-request.yml
│ └── question.yml
└── workflows
│ ├── deploy-demo.yml
│ └── publish-to-npm.yml
├── .gitignore
├── .npmignore
├── .prettierignore
├── .prettierrc
├── LICENSE
├── Makefile
├── README.md
├── assets
├── vue.png
└── wc.png
├── env.d.ts
├── examples
├── issues
│ └── 15-elevenliu123456
│ │ ├── .gitignore
│ │ ├── .prettierrc
│ │ ├── README.md
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── public
│ │ └── vite.svg
│ │ ├── src
│ │ ├── App.vue
│ │ ├── main.ts
│ │ └── vite-env.d.ts
│ │ ├── tsconfig.json
│ │ ├── tsconfig.node.json
│ │ ├── vite.config.ts
│ │ └── yarn.lock
├── vite
│ ├── .gitignore
│ ├── .prettierrc
│ ├── README.md
│ ├── index.html
│ ├── package.json
│ ├── public
│ │ └── vite.svg
│ ├── src
│ │ ├── App.vue
│ │ ├── main.ts
│ │ └── vite-env.d.ts
│ ├── tsconfig.json
│ ├── tsconfig.node.json
│ ├── vite.config.ts
│ └── yarn.lock
└── vue-cli-service
│ ├── .gitignore
│ ├── .prettierrc
│ ├── README.md
│ ├── babel.config.js
│ ├── jsconfig.json
│ ├── package.json
│ ├── public
│ └── index.html
│ ├── src
│ ├── App.vue
│ └── main.js
│ ├── vue.config.js
│ └── yarn.lock
├── index.html
├── lib
├── account.ts
├── actions
│ ├── asset.ts
│ ├── balance.ts
│ ├── block.ts
│ ├── contract.ts
│ ├── event.ts
│ ├── gas.ts
│ ├── index.ts
│ ├── message.ts
│ ├── multicall.ts
│ ├── token.ts
│ └── transaction.ts
├── chain.ts
├── enums.ts
├── event.ts
├── index.ts
├── log.ts
├── options.ts
├── plugin.ts
├── types.ts
├── utils
│ └── abi
│ │ ├── erc20.abi.ts
│ │ ├── index.ts
│ │ └── multicall.abi.ts
├── wc.ts
└── web3Modal.ts
├── package.json
├── src
├── App.vue
└── main.ts
├── tsconfig.json
├── vite.demo.config.ts
├── vite.lib.config.ts
└── yarn.lock
/.env.development:
--------------------------------------------------------------------------------
1 | VITE_G_ID=
2 |
--------------------------------------------------------------------------------
/.env.production:
--------------------------------------------------------------------------------
1 | VITE_G_ID=G-WTCZT7WPNW
2 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | examples
--------------------------------------------------------------------------------
/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | /* eslint-env node */
2 | require('@rushstack/eslint-patch/modern-module-resolution')
3 |
4 | module.exports = {
5 | root: true,
6 | extends: [
7 | 'plugin:vue/vue3-essential',
8 | 'eslint:recommended',
9 | '@vue/eslint-config-typescript',
10 | '@vue/eslint-config-prettier/skip-formatting'
11 | ],
12 | parserOptions: {
13 | ecmaVersion: 'latest'
14 | },
15 | rules: {
16 | 'vue/multi-word-component-names': 'off'
17 | },
18 | ignorePatterns: ['dist/**/*', 'demo/**/*', 'examples/**/*']
19 | }
20 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | custom: https://www.buymeacoffee.com/kolirt
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug-report.yml:
--------------------------------------------------------------------------------
1 | name: 🐞 Bug report
2 | description: Create a report to help us improve vue-web3-auth.
3 | title: '[Bug]: '
4 | labels: [bug, v2]
5 | body:
6 | - type: markdown
7 | attributes:
8 | value: |
9 | Before reporting a bug, please make sure that you have read through our [documentation](https://github.com/kolirt/vue-web3-auth?tab=readme-ov-file#web3-authentication-for-vue3-apps-based-on-walletconnect-web3modal-v2-and-wagmi) and existing [issues](https://github.com/kolirt/vue-web3-auth/issues).
10 | - type: input
11 | id: version
12 | attributes:
13 | label: Version
14 | placeholder: v2.1.0
15 | validations:
16 | required: true
17 | - type: textarea
18 | id: configuration
19 | attributes:
20 | label: Package configuration
21 | description: Show how you configured the package. You can check how to configure the package [here](https://github.com/kolirt/vue-web3-auth?tab=readme-ov-file#configuration).
22 | placeholder: |
23 | createWeb3Auth({
24 | projectId: '', // remove your projectId
25 | chains: [Chains.bsc, Chains.mainnet, Chains.polygon]
26 | })
27 | validations:
28 | required: true
29 | - type: textarea
30 | id: steps-to-reproduce
31 | attributes:
32 | label: Steps to reproduce
33 | description: |
34 | How do you trigger this bug? Please walk us through it step by step.
35 | Note that you can use [Markdown](https://guides.github.com/features/mastering-markdown/) to format lists and code.
36 | placeholder: Steps to reproduce
37 | validations:
38 | required: true
39 | - type: textarea
40 | id: bug-description
41 | attributes:
42 | label: Describe the bug
43 | description: A clear and concise description of what the bug is. If you intend to submit a PR for this issue, tell us in the description. Thanks!
44 | placeholder: Bug description
45 | validations:
46 | required: true
47 | - type: textarea
48 | id: screenshots
49 | attributes:
50 | label: Context & Screenshots (if applicable)
51 | description: |
52 | If applicable, provide any additional context or screenshots of the bug.
53 | You can drag and drop images here to add them to the issue.
54 | - type: textarea
55 | id: logs
56 | attributes:
57 | label: Logs
58 | description: |
59 | Optional if provided reproduction. Please try not to insert an image but copy paste the log text.
60 | render: shell-script
61 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: 📖 Documentation
4 | url: https://github.com/kolirt/vue-web3-auth?tab=readme-ov-file#web3-authentication-for-vue3-apps-based-on-walletconnect-web3modal-v2-and-wagmi
5 | about: Check the documentation for guides and examples.
6 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature-request.yml:
--------------------------------------------------------------------------------
1 | name: 🚀 Feature request
2 | description: Suggest a feature that will improve vue-web3-auth.
3 | title: '[Feature]: '
4 | labels: [feature request, v2]
5 | body:
6 | - type: markdown
7 | attributes:
8 | value: |
9 | Thank you for taking the time to fill out this feature request!
10 | - type: textarea
11 | id: feature-description
12 | attributes:
13 | label: Describe the feature
14 | description: A clear and concise description of what you think would be a helpful addition to vue-web3-auth, including the possible use cases and alternatives you have considered. If you have a working prototype or module that implements it, please include a link.
15 | placeholder: Feature description
16 | validations:
17 | required: true
18 | - type: checkboxes
19 | id: additional-info
20 | attributes:
21 | label: Additional information
22 | description: Additional information that helps us decide how to proceed.
23 | options:
24 | - label: I intend to submit a PR for this feature.
25 | - label: I have already implemented and/or tested this feature.
26 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/question.yml:
--------------------------------------------------------------------------------
1 | name: 💬 Question
2 | description: Ask a question about the vue-web3-auth.
3 | title: '[Question]: '
4 | labels: [question, v2]
5 | body:
6 | - type: markdown
7 | attributes:
8 | value: |
9 | Before asking a question, please make sure that you have read through our [documentation](https://github.com/kolirt/vue-web3-auth?tab=readme-ov-file#web3-authentication-for-vue3-apps-based-on-walletconnect-web3modal-v2-and-wagmi) and existing [issues](https://github.com/kolirt/vue-web3-auth/issues).
10 | - type: input
11 | id: version
12 | attributes:
13 | label: Package version
14 | description: |
15 | Leave blank if you have not yet configured the package and have not used it.
16 | placeholder: v2.1.0
17 | - type: textarea
18 | id: configuration
19 | attributes:
20 | label: Package configuration
21 | description: |
22 | Show how you configured the package. You can check how to configure the package [here](https://github.com/kolirt/vue-web3-auth?tab=readme-ov-file#configuration).
23 | Leave blank if you have not yet configured the package and have not used it.
24 | placeholder: |
25 | createWeb3Auth({
26 | projectId: '', // remove your projectId
27 | chains: [Chains.bsc, Chains.mainnet, Chains.polygon]
28 | })
29 | - type: textarea
30 | id: description
31 | attributes:
32 | label: Description
33 | validations:
34 | required: true
35 |
--------------------------------------------------------------------------------
/.github/workflows/deploy-demo.yml:
--------------------------------------------------------------------------------
1 | name: 📝 deploy demo
2 |
3 | on:
4 | push:
5 | branches:
6 | - v2
7 | paths:
8 | - src/**
9 | workflow_dispatch:
10 |
11 | permissions:
12 | contents: read
13 | pages: write
14 | id-token: write
15 |
16 | concurrency:
17 | group: 'pages'
18 | cancel-in-progress: false
19 |
20 | jobs:
21 | deploy:
22 | name: 🚀 Deploy
23 | environment:
24 | name: github-pages
25 | url: ${{ steps.deployment.outputs.page_url }}
26 | runs-on: ubuntu-latest
27 | steps:
28 | - name: 📚 Checkout
29 | uses: actions/checkout@v3
30 | - name: 🟢 Node
31 | uses: actions/setup-node@v3
32 | with:
33 | node-version: 18
34 | registry-url: 'https://registry.npmjs.org'
35 | - name: 🕵 Yarn install
36 | uses: borales/actions-yarn@v4
37 | with:
38 | cmd: install
39 | - name: 🏗 Build
40 | uses: borales/actions-yarn@v4
41 | with:
42 | cmd: build-demo
43 | - name: Setup Pages
44 | uses: actions/configure-pages@v3
45 | - name: Upload artifact
46 | uses: actions/upload-pages-artifact@v1
47 | with:
48 | path: './demo'
49 | - name: 🚀 Deploy to GitHub Pages
50 | id: deployment
51 | uses: actions/deploy-pages@v2
52 |
--------------------------------------------------------------------------------
/.github/workflows/publish-to-npm.yml:
--------------------------------------------------------------------------------
1 | name: 🚀 publish to npm
2 |
3 | on:
4 | release:
5 | types: [ published ]
6 |
7 | permissions:
8 | id-token: write
9 |
10 | jobs:
11 | release:
12 | name: 🚀 Release
13 | runs-on: ubuntu-latest
14 | steps:
15 | - name: 📚 Checkout
16 | uses: actions/checkout@v3
17 | - name: 🟢 Node
18 | uses: actions/setup-node@v3
19 | with:
20 | node-version: 18
21 | registry-url: 'https://registry.npmjs.org'
22 | - name: 🕵 Yarn install
23 | uses: borales/actions-yarn@v4
24 | with:
25 | cmd: install
26 | - name: 🏗 Build
27 | uses: borales/actions-yarn@v4
28 | with:
29 | cmd: build-lib
30 | - name: 🚀 Publish
31 | run: npm publish --provenance --access public
32 | env:
33 | NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
34 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | .DS_Store
12 | dist
13 | dist-ssr
14 | demo
15 | coverage
16 | *.local
17 |
18 | /cypress/videos/
19 | /cypress/screenshots/
20 |
21 | # Editor directories and files
22 | .vscode/*
23 | !.vscode/extensions.json
24 | .idea
25 | *.suo
26 | *.ntvs*
27 | *.njsproj
28 | *.sln
29 | *.sw?
30 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .github
2 | demo
3 | lib
4 | src
5 | .gitignore
6 | env.d.ts
7 | index.html
8 | Makefile
9 | tsconfig*
10 | yarn.lock
11 | vite.*
12 | .env
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | examples
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "bracketSpacing": true,
3 | "trailingComma": "none",
4 | "tabWidth": 2,
5 | "printWidth": 120,
6 | "semi": false,
7 | "singleQuote": true,
8 | "endOfLine": "auto",
9 | "plugins": ["prettier-plugin-organize-imports", "prettier-plugin-organize-attributes"],
10 | "attributeGroups": [
11 | "^ref",
12 | "^v-if",
13 | "^v-else",
14 | "^v-show",
15 | "^v-for",
16 | "^:?is$",
17 | "^@",
18 | "^:",
19 | "$DEFAULT",
20 | "^aria-",
21 | "^:?key$"
22 | ]
23 | }
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 kolirt
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | dev:
2 | yarn dev-demo
3 | format:
4 | yarn format
5 | check:
6 | yarn type-check && yarn lint
7 | build:
8 | yarn build-lib && yarn build-demo
9 | build-demo:
10 | yarn build-demo
11 | build-lib:
12 | yarn build-lib
13 | preview:
14 | yarn preview-demo
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |

3 |

4 |
5 |
6 | Vue web3 auth
7 |
8 | Web3 authentication for Vue3 apps based on WalletConnect Web3Modal v2 and wagmi
9 |
10 |
11 |

12 |
13 |

14 |
15 |
16 | 
17 |
18 |

19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | Simple WalletConnect Web3Modal v2 integration package for Vue3 apps.
27 |
28 | ### Versions
29 |
30 | | package version | web3modal |
31 | | -------------------------------------------------------- | -------------------------------------------------------- |
32 | | [2.x.x](https://github.com/kolirt/vue-web3-auth/tree/v2) | [v2](https://github.com/reown-com/appkit/tree/V2) |
33 |
34 | ### Table of Contents
35 |
36 | - [Versions](#versions)
37 | - [Getting started](#getting-started)
38 | - [Installation](#installation)
39 | - [Setup](#setup)
40 | - [Configuration](#configuration)
41 | - [Custom chain](#custom-chain)
42 | - [Custom rpc provider](#custom-rpc-provider)
43 | - [Usage](#usage)
44 | - [Basic usage](#basic-usage)
45 | - [Info about the user's connected wallet and wallet type](#info-about-the-users-connected-wallet-and-wallet-type)
46 | - [Connect wallet button](#connect-wallet-button)
47 | - [Switch chain](#switch-chain)
48 | - [Select chain via Web3Modal](#select-chain-via-web3modal)
49 | - [FetchGasPrice](#fetchgasprice)
50 | - [FetchBlockNumber](#fetchblocknumber)
51 | - [FetchTransaction](#fetchtransaction)
52 | - [FetchTransactionReceipt](#fetchtransactionreceipt)
53 | - [PrepareSendTransaction](#preparesendtransaction)
54 | - [SendTransaction](#sendtransaction)
55 | - [WaitForTransaction](#waitfortransaction)
56 | - [SignMessage](#signmessage)
57 | - [Multicall](#multicall)
58 | - [FetchBalance](#fetchbalance)
59 | - [FetchToken](#fetchtoken)
60 | - [ReadContract](#readcontract)
61 | - [WriteContract](#writecontract)
62 | - [EstimateWriteContractGas](#estimatewritecontractgas)
63 | - [ParseEvents](#parseevents)
64 | - [WatchContractEvent](#watchcontractevent)
65 | - [WatchAsset](#watchasset)
66 | - [Composable](#composable)
67 | - [UseFetchBalance](#usefetchbalance)
68 | - [Demo](#demo)
69 | - [Example](#example)
70 | - [Faq](#faq)
71 | - [License](#license)
72 | - [Other packages](#other-packages)
73 |
74 |
75 |
76 |
77 |
78 | # Getting started
79 |
80 | ## Installation
81 |
82 | Use yarn or npm to install the package `@kolirt/vue-web3-auth`.
83 |
84 | ```bash
85 | npm install --save @kolirt/vue-web3-auth
86 |
87 | yarn add @kolirt/vue-web3-auth
88 | ```
89 |
90 | ## Setup
91 |
92 | ### Configuration
93 |
94 | Add dependencies to your `main.js`:
95 |
96 | ```javascript
97 | import { createApp } from 'vue'
98 | import { Chains, createWeb3Auth } from '@kolirt/vue-web3-auth'
99 |
100 | const app = createApp({...})
101 |
102 | app.use(createWeb3Auth({
103 | projectId: '', // generate here https://cloud.walletconnect.com/ and turn on 'Supports Sign v2'
104 | chains: [
105 | Chains.bsc,
106 | Chains.mainnet,
107 | Chains.polygon
108 | ]
109 | }))
110 |
111 | app.mount('#app')
112 | ```
113 |
114 | ### Custom chain
115 |
116 | ```ts
117 | import { type Chain } from '@kolirt/vue-web3-auth'
118 |
119 | const bsc: Chain = {
120 | id: 56,
121 | name: 'BNB Smart Chain',
122 | network: 'bsc',
123 | nativeCurrency: {
124 | decimals: 18,
125 | name: 'BNB',
126 | symbol: 'BNB'
127 | },
128 | rpcUrls: {
129 | default: {
130 | http: ['https://rpc.ankr.com/bsc'],
131 | webSocket: ['wss://bsc-ws-node.nariox.org:443']
132 | },
133 | public: {
134 | http: ['https://rpc.ankr.com/bsc'],
135 | webSocket: ['wss://bsc-ws-node.nariox.org:443']
136 | }
137 | },
138 | blockExplorers: {
139 | etherscan: {
140 | name: 'BscScan',
141 | url: 'https://bscscan.com'
142 | },
143 | default: {
144 | name: 'BscScan',
145 | url: 'https://bscscan.com'
146 | }
147 | },
148 | contracts: {
149 | multicall3: {
150 | address: '0xca11bde05977b3631167028862be2a173976ca11',
151 | blockCreated: 15921452
152 | }
153 | }
154 | }
155 | ```
156 |
157 | ### Custom rpc provider
158 |
159 | By default, the package uses the walletconnect rpc provider. If you want to use a custom rpc from the chain, you can set the `enableCustomProvider` option to `true`.
160 |
161 | ```ts
162 | app.use(createWeb3Auth({
163 | enableCustomProvider: true
164 | })
165 | ```
166 |
167 | # Usage
168 |
169 | ## Basic usage
170 |
171 | ### Info about the user's connected wallet and wallet type
172 |
173 | ```ts
174 | import { account } from '@kolirt/vue-web3-auth'
175 |
176 | account.connected // if connected
177 | account.address // current account address
178 | account.shortAddress // current account address with 3 dots
179 | account.wallet.id // current wallet id
180 | account.wallet.name // current wallet name
181 | ```
182 |
183 | ### Connect wallet button
184 |
185 | ```vue
186 |
189 |
190 |
191 |
192 |
195 |
196 |
197 |
198 |
199 | ```````
200 |
201 | ### Switch chain
202 | To switch the chain, you need to add it during [configuration](#configuration).
203 |
204 | ```vue
205 |
208 |
209 |
210 |
211 |
212 | ```
213 |
214 | ### Select chain via Web3Modal
215 |
216 | ```vue
217 |
220 |
221 |
222 |
223 |
224 | ```
225 |
226 | ### FetchGasPrice
227 |
228 | ```ts
229 | import { fetchGasPrice } from '@kolirt/vue-web3-auth'
230 |
231 | const data = await fetchGasPrice()
232 |
233 | /**
234 | * Result in data
235 | *
236 | * {
237 | * formatted: {
238 | * gasPrice: '3'
239 | * },
240 | * gasPrice: 3000000000n
241 | * }
242 | */
243 | ```
244 |
245 | ### FetchBlockNumber
246 |
247 | ```ts
248 | import { fetchBlockNumber } from '@kolirt/vue-web3-auth'
249 |
250 | const data = await fetchBlockNumber()
251 |
252 | /**
253 | * Result in data
254 | *
255 | * 29288229n
256 | */
257 | ```
258 |
259 | ### FetchTransaction
260 |
261 | ```ts
262 | import { fetchTransaction } from '@kolirt/vue-web3-auth'
263 |
264 | const transaction = await fetchTransaction({
265 | hash: '0x7ed8dc64f54ae43f4d53173e95aa929c52de44ec5cea8c28246989914ed7f4fb'
266 | })
267 | ```
268 |
269 | ### FetchTransactionReceipt
270 |
271 | ```ts
272 | import { fetchTransactionReceipt } from '@kolirt/vue-web3-auth'
273 |
274 | const transactionReceipt = await fetchTransactionReceipt({
275 | hash: '0x7ed8dc64f54ae43f4d53173e95aa929c52de44ec5cea8c28246989914ed7f4fb'
276 | })
277 | ```
278 |
279 | ### PrepareSendTransaction
280 |
281 | ```ts
282 | import { prepareSendTransaction } from '@kolirt/vue-web3-auth'
283 |
284 | const preparedTxn = await prepareSendTransaction({
285 | to: '0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9',
286 | value: 1n
287 | })
288 | ```
289 |
290 | ### SendTransaction
291 |
292 | ```ts
293 | import { sendTransaction } from '@kolirt/vue-web3-auth'
294 |
295 | const txn = await sendTransaction({
296 | to: '0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9',
297 | value: 1n
298 | })
299 | ```
300 |
301 | ### WaitForTransaction
302 |
303 | ```ts
304 | import { waitForTransaction } from '@kolirt/vue-web3-auth'
305 |
306 | const transactionReceipt = await waitForTransaction({
307 | hash: '0x7ed8dc64f54ae43f4d53173e95aa929c52de44ec5cea8c28246989914ed7f4fb',
308 | })
309 | ```
310 |
311 | ### SignMessage
312 |
313 | ```ts
314 | import { signMessage } from '@kolirt/vue-web3-auth'
315 |
316 | const signature = await signMessage('test message')
317 | ```
318 |
319 | ### Multicall
320 |
321 | ```ts
322 | import { chain, multicall, multicallABI } from '@kolirt/vue-web3-auth'
323 |
324 | let data = await multicall({
325 | calls: [
326 | {
327 | abi: multicallABI,
328 | contractAddress: chain.value.contracts.multicall3.address,
329 | calls: [
330 | ['getEthBalance', ['0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9']],
331 | ['getEthBalance', ['0x295e26495CEF6F69dFA69911d9D8e4F3bBadB89B']],
332 | ['getEthBalance', ['0x2465176C461AfB316ebc773C61fAEe85A6515DAA']]
333 | ]
334 | }
335 | ]
336 | })
337 |
338 | /**
339 | * Result in data
340 | *
341 | * [
342 | * {result: 1908669631824871303n, status: "success"},
343 | * {result: 133515691552422277n, status: "success"},
344 | * {result: 2080909582708869960n, status: "success"}
345 | * ]
346 | */
347 | ```
348 |
349 | ### FetchBalance
350 |
351 | ```ts
352 | import { fetchBalance } from '@kolirt/vue-web3-auth'
353 |
354 | let bnbBalance = await fetchBalance({
355 | address: '0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9'
356 | })
357 |
358 | /**
359 | * Result in bnbBalance
360 | *
361 | * {
362 | * decimals: 18,
363 | * formatted: '1.908669631824871303',
364 | * symbol: 'BNB',
365 | * value: 1908669631824871303n
366 | * }
367 | */
368 |
369 | let tokenBalance = await fetchBalance({
370 | address: '0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9',
371 | token: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'
372 | })
373 |
374 | /**
375 | * Result in tokenBalance
376 | *
377 | * {
378 | * decimals: 18,
379 | * formatted: '0',
380 | * symbol: 'WBNB',
381 | * value: 0n
382 | * }
383 | */
384 | ```
385 |
386 | ### FetchToken
387 |
388 | ```ts
389 | import { fetchToken } from '@kolirt/vue-web3-auth'
390 |
391 | let data = await fetchToken({
392 | address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'
393 | })
394 |
395 | /**
396 | * Result in data
397 | *
398 | * {
399 | * address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
400 | * decimals: 18,
401 | * name: 'Wrapped BNB',
402 | * symbol: 'WBNB',
403 | * totalSupply: {
404 | * formatted: '2538454.736169014001284694',
405 | * value: 2538454736169014001284694n
406 | * }
407 | * }
408 | */
409 | ```
410 |
411 | ### ReadContract
412 |
413 | ```ts
414 | import { erc20ABI, readContract } from '@kolirt/vue-web3-auth'
415 |
416 | let data = await readContract({
417 | address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', // wbnb on bsc
418 | abi: erc20ABI,
419 | functionName: 'balanceOf',
420 | args: ['0x36696169c63e42cd08ce11f5deebbcebae652050']
421 | })
422 |
423 | /**
424 | * Result in data
425 | *
426 | * 107109316688516684525777n
427 | */
428 | ```
429 |
430 | ### WriteContract
431 |
432 | ```ts
433 | import { erc20ABI, writeContract } from '@kolirt/vue-web3-auth'
434 |
435 | await writeContract({
436 | abi: erc20ABI,
437 | address: '0x55d398326f99059fF775485246999027B3197955',
438 | functionName: 'approve',
439 | args: ['0x685B1ded8013785d6623CC18D214320b6Bb64759', 100]
440 | }).then(async (data) => {
441 | console.log('hash', data.hash)
442 |
443 | await data.wait()
444 |
445 | console.log('transaction successfully')
446 | })
447 | ```
448 |
449 | ### EstimateWriteContractGas
450 |
451 | ```ts
452 | import { erc20ABI, estimateWriteContractGas } from '@kolirt/vue-web3-auth'
453 |
454 | const gas = await estimateWriteContractGas({
455 | abi: erc20ABI,
456 | address: '0x55d398326f99059fF775485246999027B3197955',
457 | functionName: 'approve',
458 | args: ['0x685B1ded8013785d6623CC18D214320b6Bb64759', 100]
459 | }).catch((e) => {})
460 | ```
461 |
462 | ### ParseEvents
463 |
464 | ```ts
465 | import { erc20ABI, fetchTransactionReceipt, parseEvents } from '@kolirt/vue-web3-auth'
466 |
467 | const transactionReceipt = await fetchTransactionReceipt({
468 | hash: '0x2a328737e94bb243b1ff64792ae68cd6c179797dc1de1e092c96137f0d3404c3'
469 | })
470 |
471 | const events = parseEvents({ abi: erc20ABI }, transactionReceipt)
472 | /**
473 | * Result in events
474 | *
475 | * [
476 | * {
477 | * args: {
478 | * owner: '0xaA916B4a4cDbEFC045fa24542673F500a11F5413',
479 | * spender: '0x023963f7e755bE4F743047183d1F49C31E84AEa4',
480 | * value: 1000000000000000000n
481 | * },
482 | * eventName: 'Approval'
483 | * }
484 | * ]
485 | */
486 | ```
487 |
488 | ### WatchContractEvent
489 |
490 | ```ts
491 | import { erc20ABI, watchContractEvent } from '@kolirt/vue-web3-auth'
492 |
493 | const unwatch = watchContractEvent(
494 | {
495 | address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
496 | abi: erc20ABI,
497 | eventName: 'Transfer'
498 | },
499 | (log) => {
500 | console.log(log)
501 | }
502 | )
503 | ```
504 |
505 | ### WatchAsset
506 |
507 | ```ts
508 | import { watchAsset } from '@kolirt/vue-web3-auth'
509 |
510 | const result = watchAsset({
511 | address: '0x6b175474e89094c44da98b954eedeac495271d0f',
512 | decimals: 18,
513 | symbol: 'DAI'
514 | })
515 | ```
516 |
517 | ## Composable
518 |
519 | ### UseFetchBalance
520 |
521 | ```ts
522 | import { useFetchBalance } from '@kolirt/vue-web3-auth'
523 |
524 | // use `fetch` for manual init when `disableAutoFetch` is `true`
525 | const { loaded, fetching, data, fetch, reload, disableAutoReload } = useFetchBalance(
526 | {
527 | address: '0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9'
528 | },
529 | {
530 | disableAutoFetch: false,
531 | autoReloadTime: 30000,
532 | disableAutoReload: false
533 | }
534 | )
535 | ```
536 |
537 | # Demo
538 |
539 | [Demo here](https://kolirt.github.io/vue-web3-auth/)
540 |
541 | # Example
542 |
543 | [Example here](https://github.com/kolirt/vue-web3-auth/tree/v2/examples)
544 |
545 | # FAQ
546 |
547 | Check closed [issues](https://github.com/kolirt/vue-web3-auth/issues) to get answers for most asked questions.
548 |
549 | # License
550 |
551 | [MIT](https://github.com/kolirt/vue-web3-auth/tree/v2/LICENSE)
552 |
553 | # Other packages
554 |
555 | Check out my other projects on my [GitHub profile](https://github.com/kolirt).
556 |
--------------------------------------------------------------------------------
/assets/vue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kolirt/vue-web3-auth/8ec752113cb4fc879823ce1da57590227579af34/assets/vue.png
--------------------------------------------------------------------------------
/assets/wc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kolirt/vue-web3-auth/8ec752113cb4fc879823ce1da57590227579af34/assets/wc.png
--------------------------------------------------------------------------------
/env.d.ts:
--------------------------------------------------------------------------------
1 | declare module '*.vue' {
2 | import type { DefineComponent } from 'vue'
3 | const component: DefineComponent<{}, {}, any>
4 | export default component
5 | }
6 |
--------------------------------------------------------------------------------
/examples/issues/15-elevenliu123456/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/examples/issues/15-elevenliu123456/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "bracketSpacing": true,
3 | "trailingComma": "none",
4 | "tabWidth": 2,
5 | "printWidth": 120,
6 | "semi": false,
7 | "singleQuote": true,
8 | "endOfLine": "auto",
9 | "plugins": ["prettier-plugin-organize-imports", "prettier-plugin-organize-attributes"]
10 | }
11 |
--------------------------------------------------------------------------------
/examples/issues/15-elevenliu123456/README.md:
--------------------------------------------------------------------------------
1 | # Vue 3 + TypeScript + Vite
2 |
3 | This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `
12 |