Skip to content

Commit c430c94

Browse files
committed
add fetchGasPrice
1 parent c104267 commit c430c94

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Simple WalletConnect v2 integration package for Vue3 apps.
1313
- [Setup](#setup)
1414
- [Usage](#usage)
1515
- [Connect wallet button](#connect-wallet-button)
16+
- [FetchGasPrice](#fetchgasprice)
1617
- [Multicall](#multicall)
1718
- [FetchBalance](#fetchbalance)
1819
- [FetchToken](#fetchtoken)
@@ -79,6 +80,26 @@ import {account, disconnect, connect} from '@kolirt/vue-web3-auth'
7980
</template>
8081
```
8182

83+
## FetchGasPrice
84+
```js
85+
import {fetchGasPrice} from '@kolirt/vue-web3-auth'
86+
87+
let data = await fetchGasPrice()
88+
89+
/**
90+
* Result in data
91+
*
92+
* {
93+
* formatted: {
94+
* gasPrice: '3',
95+
* maxFeePerGas: null,
96+
* maxPriorityFeePerGas: null
97+
* },
98+
* gasPrice: 3000000000n
99+
* }
100+
*/
101+
```
102+
82103
## Multicall
83104
```ts
84105
import {multicallABI, multicall, chain} from '@kolirt/vue-web3-auth'

lib/gas.ts

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

lib/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export {
3939
estimateWriteContractGas
4040
} from './contract'
4141

42+
export {
43+
fetchGasPrice
44+
} from './gas'
45+
4246
export {
4347
multicall
4448
} from './multicall'

lib/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,9 @@ export type FetchToken = {
9696
chainId?: number
9797
address: `0x${string}`
9898
formatUnits?: Unit
99+
}
100+
101+
export type FetchFeeData = {
102+
chainId?: number
103+
formatUnits?: Unit
99104
}

0 commit comments

Comments
 (0)