Skip to content

Commit fc1fe4d

Browse files
Allow injecting existing PublicClient into SemaphoreViem (#1006)
* refactor: allow injecting existing PublicClient into SemaphoreViem * fix: remove comment
1 parent feb8c9c commit fc1fe4d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/data/src/types/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Chain, Transport } from "viem"
1+
import { Chain, PublicClient, Transport } from "viem"
22

33
export type EthersNetwork =
44
| "mainnet"
@@ -65,4 +65,5 @@ export type ViemOptions = {
6565
transport?: Transport // Transport from viem
6666
chain?: Chain // Chain from viem
6767
apiKey?: string
68+
publicClient?: PublicClient
6869
}

packages/data/src/viem.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ export default class SemaphoreViem {
117117
throw new Error(`Network '${networkOrEthereumURL}' needs a Semaphore contract address`)
118118
}
119119

120-
// Create the public client
121120
let transport: Transport
122121

123122
if (options.transport) {
@@ -131,10 +130,12 @@ export default class SemaphoreViem {
131130
this._options = options
132131

133132
// Create the public client
134-
this._client = createPublicClient({
135-
transport,
136-
chain: options.chain as Chain
137-
})
133+
this._client =
134+
options.publicClient ??
135+
createPublicClient({
136+
transport,
137+
chain: options.chain as Chain
138+
})
138139

139140
// Create the contract instance
140141
this._contract = getContract({

0 commit comments

Comments
 (0)