Skip to content

Commit

Permalink
fix injected provider contract instance creation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed May 23, 2024
1 parent 06e44b6 commit f8f0f73
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/helpers/contracts.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,12 @@ const createContract = <F extends AbstractFactoryClass>(
provider: RawProvider,
factoryClass: F,
): AbstractFactoryClassReturnType<F> => {
let isSigner = false

try {
const signer = (provider as unknown as providers.Web3Provider).getSigner()

isSigner = !!signer._address
} catch (error) {
isSigner = false
}

const contractInstance = factoryClass.connect(
address,
(isSigner
? new providers.Web3Provider(
provider as providers.ExternalProvider,
'any',
)
: provider) as unknown as providers.Web3Provider,
new providers.Web3Provider(
provider as providers.ExternalProvider,
'any',
) as unknown as providers.Web3Provider,
) as ReturnType<F['connect']>

const contractInterface = factoryClass.createInterface() as ReturnType<
Expand Down

0 comments on commit f8f0f73

Please sign in to comment.