TypeChain icon indicating copy to clipboard operation
TypeChain copied to clipboard

[Bug] Type 'Contract' is not assignable to type 'SomeContract'.

Open nonwip opened this issue 4 years ago • 1 comments

I followed the official web3 example, but for some reason it throws a bunch of errors for me, because my case-scenario has deploy and send chained to the instance.

Screenshot 2021-12-18 at 13 36 38

If I do it with this approach, then I don't have the deployed contract stored for the future interaction.

let factory: FactoryContext

// ... later on
factory = new web3.eth.Contract(FactoryArtifact.abi) as unknown as FactoryContext

await factory.deploy({ ... }}.send({ ... })

// ... later on
expect(factory.options.address).toBeTruthy() // error (undefined)

So I had to @ts-ignore the line, for now. Is there a solution to this that's not documented, because I'm struggling to find the way?

nonwip avatar Dec 18 '21 12:12 nonwip

UPDATE

This appears to be working. Is this how I'm supposed to do it anyway?

let factory: FactoryContext

factory = (await new web3.eth.Contract(FactoryArtifact.abi)
    .deploy({ data: FactoryArtifact.evm.bytecode.object })
    .send({ from: accounts[0], gas: 3_000_000 })) as unknown as FactoryContext

nonwip avatar Dec 18 '21 12:12 nonwip