Skip to content

Commit c104267

Browse files
committed
add fetchToken
1 parent ecc0468 commit c104267

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Simple WalletConnect v2 integration package for Vue3 apps.
1515
- [Connect wallet button](#connect-wallet-button)
1616
- [Multicall](#multicall)
1717
- [FetchBalance](#fetchbalance)
18+
- [FetchToken](#fetchtoken)
1819
- [ReadContract](#readcontract)
1920
- [WriteContract](#writecontract)
2021
- [EstimateWriteContractGas](#estimatewritecontractgas)
@@ -143,6 +144,30 @@ let tokenBalance = await fetchBalance({
143144
*/
144145
```
145146

147+
## FetchToken
148+
```js
149+
import {fetchToken} from '@kolirt/vue-web3-auth'
150+
151+
let data = await fetchToken({
152+
address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'
153+
})
154+
155+
/**
156+
* Result in data
157+
*
158+
* {
159+
* address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
160+
* decimals: 18,
161+
* name: 'Wrapped BNB',
162+
* symbol: 'WBNB',
163+
* totalSupply: {
164+
* formatted: '2538454.736169014001284694',
165+
* value: 2538454736169014001284694n
166+
* }
167+
* }
168+
*/
169+
```
170+
146171
## ReadContract
147172

148173
```ts

lib/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Chains from '@wagmi/core/chains'
2+
import exp from 'constants'
23

34
export type {Chain, Options} from './types'
45

@@ -28,6 +29,10 @@ export {
2829
fetchBalance
2930
} from './balance'
3031

32+
export {
33+
fetchToken
34+
} from './token'
35+
3136
export {
3237
readContract,
3338
writeContract,

lib/token.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type {FetchToken} from './types'
2+
import {fetchToken as masterFetchToken} from '@wagmi/core'
3+
import {chain} from './chain'
4+
5+
export function fetchToken(data: FetchToken) {
6+
return masterFetchToken({
7+
chainId: data.chainId || chain.value.id,
8+
address: data.address,
9+
formatUnits: data.formatUnits
10+
})
11+
}

lib/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,10 @@ export type FetchBalance = {
9090
address: `0x${string}`
9191
formatUnits?: Unit
9292
token?: `0x${string}`
93+
}
9394

95+
export type FetchToken = {
96+
chainId?: number
97+
address: `0x${string}`
98+
formatUnits?: Unit
9499
}

0 commit comments

Comments
 (0)