Allow injecting existing PublicClient into SemaphoreViem (#1006)

* refactor: allow injecting existing PublicClient into SemaphoreViem

* fix: remove comment
This commit is contained in:
aritra
2025-07-17 17:18:13 +05:30
committed by GitHub
parent feb8c9c97d
commit fc1fe4d086
2 changed files with 8 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
import { Chain, Transport } from "viem"
import { Chain, PublicClient, Transport } from "viem"
export type EthersNetwork =
| "mainnet"
@@ -65,4 +65,5 @@ export type ViemOptions = {
transport?: Transport // Transport from viem
chain?: Chain // Chain from viem
apiKey?: string
publicClient?: PublicClient
}

View File

@@ -117,7 +117,6 @@ export default class SemaphoreViem {
throw new Error(`Network '${networkOrEthereumURL}' needs a Semaphore contract address`)
}
// Create the public client
let transport: Transport
if (options.transport) {
@@ -131,10 +130,12 @@ export default class SemaphoreViem {
this._options = options
// Create the public client
this._client = createPublicClient({
transport,
chain: options.chain as Chain
})
this._client =
options.publicClient ??
createPublicClient({
transport,
chain: options.chain as Chain
})
// Create the contract instance
this._contract = getContract({