Skip to content

Commit d2ba801

Browse files
committed
update sendTransaction; add prepareSendTransaction and waitForTransaction
1 parent dbfb9e6 commit d2ba801

File tree

6 files changed

+88
-47
lines changed

6 files changed

+88
-47
lines changed

README.md

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ Simple WalletConnect Web3Modal v2 integration package for Vue3 apps.
3232
- [FetchBlockNumber](#fetchblocknumber)
3333
- [FetchTransaction](#fetchtransaction)
3434
- [FetchTransactionReceipt](#fetchtransactionreceipt)
35+
- [PrepareSendTransaction](#preparesendtransaction)
3536
- [SendTransaction](#sendtransaction)
37+
- [WaitForTransaction](#waitfortransaction)
3638
- [SignMessage](#signmessage)
3739
- [Multicall](#multicall)
3840
- [FetchBalance](#fetchbalance)
@@ -205,10 +207,10 @@ import { selectChain } from '@kolirt/vue-web3-auth'
205207
206208
### FetchGasPrice
207209
208-
```js
210+
```ts
209211
import { fetchGasPrice } from '@kolirt/vue-web3-auth'
210212

211-
let data = await fetchGasPrice()
213+
const data = await fetchGasPrice()
212214

213215
/**
214216
* Result in data
@@ -224,10 +226,10 @@ let data = await fetchGasPrice()
224226
225227
### FetchBlockNumber
226228
227-
```js
229+
```ts
228230
import { fetchBlockNumber } from '@kolirt/vue-web3-auth'
229231

230-
let data = await fetchBlockNumber()
232+
const data = await fetchBlockNumber()
231233

232234
/**
233235
* Result in data
@@ -238,38 +240,59 @@ let data = await fetchBlockNumber()
238240
239241
### FetchTransaction
240242
241-
```js
243+
```ts
242244
import { fetchTransaction } from '@kolirt/vue-web3-auth'
243245

244-
let transaction = await fetchTransaction({
246+
const transaction = await fetchTransaction({
245247
hash: '0x7ed8dc64f54ae43f4d53173e95aa929c52de44ec5cea8c28246989914ed7f4fb'
246248
})
247249
```
248250
249-
### fetchTransactionReceipt
251+
### FetchTransactionReceipt
250252
251-
```js
253+
```ts
252254
import { fetchTransactionReceipt } from '@kolirt/vue-web3-auth'
253255

254-
let transactionReceipt = await fetchTransactionReceipt({
256+
const transactionReceipt = await fetchTransactionReceipt({
255257
hash: '0x7ed8dc64f54ae43f4d53173e95aa929c52de44ec5cea8c28246989914ed7f4fb'
256258
})
257259
```
258260
261+
### PrepareSendTransaction
262+
263+
```ts
264+
import { prepareSendTransaction } from '@kolirt/vue-web3-auth'
265+
266+
const preparedTxn = await prepareSendTransaction({
267+
to: '0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9',
268+
value: 1n
269+
})
270+
```
271+
259272
### SendTransaction
260273
261-
```js
274+
```ts
262275
import { sendTransaction } from '@kolirt/vue-web3-auth'
263276

264-
let txn = await sendTransaction({
277+
const txn = await sendTransaction({
265278
to: '0x2D4C407BBe49438ED859fe965b140dcF1aaB71a9',
266279
value: 1n
267280
})
268281
```
269282
283+
### WaitForTransaction
284+
285+
```ts
286+
import { waitForTransaction } from '@kolirt/vue-web3-auth'
287+
288+
const transactionReceipt = await waitForTransaction({
289+
hash: '0x7ed8dc64f54ae43f4d53173e95aa929c52de44ec5cea8c28246989914ed7f4fb',
290+
})
291+
```
292+
270293
### SignMessage
271294
272-
```js
295+
```ts
273296
import { signMessage } from '@kolirt/vue-web3-auth'
274297

275298
const signature = await signMessage('test message')
@@ -307,7 +330,7 @@ let data = await multicall({
307330
308331
### FetchBalance
309332
310-
```js
333+
```ts
311334
import { fetchBalance } from '@kolirt/vue-web3-auth'
312335

313336
let bnbBalance = await fetchBalance({
@@ -344,7 +367,7 @@ let tokenBalance = await fetchBalance({
344367
345368
### FetchToken
346369
347-
```js
370+
```ts
348371
import { fetchToken } from '@kolirt/vue-web3-auth'
349372

350373
let data = await fetchToken({
@@ -420,7 +443,7 @@ const gas = await estimateWriteContractGas({
420443
421444
### ParseEvents
422445
423-
```js
446+
```ts
424447
import { erc20ABI, fetchTransactionReceipt, parseEvents } from '@kolirt/vue-web3-auth'
425448

426449
const transactionReceipt = await fetchTransactionReceipt({
@@ -446,7 +469,7 @@ const events = parseEvents({ abi: erc20ABI }, transactionReceipt)
446469
447470
### WatchContractEvent
448471
449-
```js
472+
```ts
450473
import { erc20ABI, watchContractEvent } from '@kolirt/vue-web3-auth'
451474

452475
const unwatch = watchContractEvent(
@@ -463,7 +486,7 @@ const unwatch = watchContractEvent(
463486
464487
### WatchAsset
465488
466-
```js
489+
```ts
467490
import { watchAsset } from '@kolirt/vue-web3-auth'
468491

469492
const result = watchAsset({
@@ -477,7 +500,7 @@ const result = watchAsset({
477500
478501
### UseFetchBalance
479502
480-
```js
503+
```ts
481504
import { useFetchBalance } from '@kolirt/vue-web3-auth'
482505

483506
// use `fetch` for manual init when `disableAutoFetch` is `true`

lib/account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const state = reactive<AccountState>({
1111
currentAccount: null
1212
})
1313

14-
const accountState = reactive<ConnectedAccount>({
14+
const accountState = reactive<ConnectedAccount>({
1515
connected: false,
1616
address: undefined,
1717
shortAddress: undefined,

lib/actions/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ export { multicall } from './multicall'
1616

1717
export { fetchToken } from './token'
1818

19-
export { fetchTransaction, fetchTransactionReceipt, sendTransaction } from './transaction'
19+
export {
20+
fetchTransaction,
21+
fetchTransactionReceipt,
22+
prepareSendTransaction,
23+
sendTransaction,
24+
waitForTransaction
25+
} from './transaction'

lib/actions/transaction.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import {
22
getPublicClient,
33
fetchTransaction as masterFetchTransaction,
4+
prepareSendTransaction as masterPrepareSendTransaction,
45
sendTransaction as masterSendTransaction,
5-
waitForTransaction
6+
waitForTransaction as masterWaitForTransaction
67
} from '@wagmi/core'
78

89
import { chain } from '../chain'
9-
import type { FetchTransaction, FetchTransactionReceipt, SendTransaction } from '../types'
10+
import type {
11+
FetchTransaction,
12+
FetchTransactionReceipt,
13+
PrepareSendTransaction,
14+
SendTransaction,
15+
WaitTransaction
16+
} from '../types'
1017

1118
export function fetchTransaction(data: FetchTransaction) {
1219
return masterFetchTransaction({
@@ -23,22 +30,23 @@ export function fetchTransactionReceipt(data: FetchTransactionReceipt) {
2330
})
2431
}
2532

26-
export async function sendTransaction(data: SendTransaction) {
27-
const { hash } = await masterSendTransaction({
33+
export function prepareSendTransaction(data: PrepareSendTransaction) {
34+
return masterPrepareSendTransaction({
2835
chainId: data.chainId || chain.value.id,
29-
to: data.to,
30-
account: data.account,
31-
gas: data.gas,
32-
gasPrice: data.gasPrice,
33-
maxFeePerGas: data.maxFeePerGas,
34-
maxPriorityFeePerGas: data.maxPriorityFeePerGas,
35-
nonce: data.nonce,
36-
value: data.value
36+
...data
3737
})
38+
}
39+
40+
export function sendTransaction(data: SendTransaction) {
41+
return masterSendTransaction({
42+
chainId: data.chainId || chain.value.id,
43+
...data
44+
})
45+
}
3846

39-
return waitForTransaction({
47+
export function waitForTransaction(data: WaitTransaction) {
48+
return masterWaitForTransaction({
4049
chainId: data.chainId || chain.value.id,
41-
hash,
42-
confirmations: data.confirmations || 1
50+
...data
4351
})
4452
}

lib/types.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import type { Chain, GetAccountResult, Unit } from '@wagmi/core'
1+
import type {
2+
Chain,
3+
GetAccountResult,
4+
PrepareSendTransactionArgs,
5+
SendTransactionArgs,
6+
Unit,
7+
WaitForTransactionArgs
8+
} from '@wagmi/core'
29
import type { ThemeCtrlState } from '@web3modal/core'
310
import type { EthereumClient } from '@web3modal/ethereum'
411
import type { WatchAssetParams } from 'viem/src/types/eip1193'
@@ -171,15 +178,12 @@ export type FetchTransactionReceipt = {
171178
hash: `0x${string}`
172179
}
173180

174-
export type SendTransaction = {
175-
chainId?: number
176-
to: string
177-
account?: `0x${string}`
178-
gas?: bigint
179-
gasPrice?: bigint
180-
maxFeePerGas?: bigint
181-
maxPriorityFeePerGas?: bigint
182-
nonce?: number
181+
export type PrepareSendTransaction = Omit<PrepareSendTransactionArgs, 'walletClient'> & {
182+
value?: bigint
183+
}
184+
185+
export type SendTransaction = SendTransactionArgs & {
183186
value?: bigint
184-
confirmations?: number
185187
}
188+
189+
export type WaitTransaction = WaitForTransactionArgs

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": "2.1.1",
3+
"version": "2.2.1",
44
"description": "Web3 authentication for Vue3 apps based on WalletConnect Web3Modal v2",
55
"author": "kolirt",
66
"license": "MIT",

0 commit comments

Comments
 (0)