question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find name 'artifacts', 'contract' after upgrading to typechain v2 [truffle v5]

See original GitHub issue

Hey, First and foremost, thank you so much for everyone’s work here. It’s great and extremely helpful.

I’ve built a dapp boilerplate and I’ve been upgrading it recently to have something a bit different. Throughout that, I’ve upgraded typechain to v2, and all the other dependencies attached to it. But because of that, I now get some errors as described below.

Could you guys help me, please? I’ll be very thankful.

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.

TSError: ⨯ Unable to compile TypeScript:
test/SimpleStorage.test.ts:4:23 - error TS2304: Cannot find name 'artifacts'.

4 const SimpleStorage = artifacts.require('SimpleStorage');
                        ~~~~~~~~~
test/SimpleStorage.test.ts:8:1 - error TS2304: Cannot find name 'contract'.

8 contract('SimpleStorage', (accounts) => {
  ~~~~~~~~
test/SimpleStorage.test.ts:8:28 - error TS7006: Parameter 'accounts' implicitly has an 'any' type.

8 contract('SimpleStorage', (accounts) => {
                             ~~~~~~~~

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
AbstractFruitFactorycommented, Aug 7, 2020

The way I fixed this was to use the tsconfig.json file here

https://github.com/ethereum-ts/truffle-typechain-example/blob/master/tsconfig.json

And then I changed truffle-contracts to truffle-typings, under types.

You will need the truffle-typings package installed in your project.

2reactions
junderwcommented, Jul 12, 2020

Having the exact same issue…

I had a similar issue with another project using jest, and the solution was something along the lines of adding the global libraries in the jest config file.

The funny thing in my situation is that the linters in my IDE are perfectly happy… They get all the types fine, autocomplete and everything.

But when I run truffle test all of the assumed global variables dealing with truffle / the generated types are forgotten apparently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find name 'artifacts', 'contract' after upgrading ... - GitHub
I've built a dapp boilerplate and I've been upgrading it recently to have something a bit different. Throughout that, I've upgraded typechain to...
Read more >
Truffle migration with TypeScript - Ethereum Stack Exchange
migrations/2_deploy_contracts.ts:10:18 - error TS2304: Cannot find name 'artifacts'. 10 const Fallback = artifacts.require('Fallback');.
Read more >
Truffle can not find artifacts error | Edureka Community
I have written a smart contract and try to run it using truffle. When I try to migrate the project, I am getting...
Read more >
hardhat-typechain - 登链社区
TypeChain gives you Typescript bindings for your smart contracts. Now, your tests and frontend code can be typesafe and magically autocomplete smart contract...
Read more >
Typescript Test Support with Typechain/truffle-v5 type mismatch
Hey guys! I'm trying to enable typescript support for my ERC1155 Upgradable via @typechain/truffle-v5. It is a bit of an overhead since ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found