“networks” entry not added to the contract's json after npx oz create when changing the artifactsDir in .openzeppelin/project.json

Hi @abcoathup,

It seems like if I change the artifactsDir in .openzeppelin/project.json
the “networks” entry does not get added to the contract json after npx oz create

2 Likes

Hi @vikram,

I am not familiar with the networks entry in contract.json.

When I tried migrating a contract using truffle, truffle populated the networks entry, so I was wondering if this was specific to Truffle?

1 Like

The networks entry looks some thing like

  "networks": {
    "1582461946241": {
      "links": {},
      "events": {},
      "address": "0x4Bb92bc7B3c93D37db885b3fA237b1458C923321",
      "updated_at": 1582462011780
    },

This is present in the json of each contract.
json file get created when we compile
and the “networks” entry gets updated when we deploy

Since I am using openzeppelin-cli for deployment this entry goes missing if I alter the artifactsDir in .openzeppelin/project.json

I am not using truffle to deploy.

And since you have mentioned above that " migrating a contract using truffle, truffle populated the networks entry," …and I hope you did set the contracts_build_directory in truffle-config.js to some thing different than the default “build/contracts”, This than means truffle works good. FYI, I have not tested with truffle migrate since I am using upgradable contracts.

And so the problem must be in openzeppelin-cli

2 Likes

Hey @vikram! Thanks for reporting the issue. I can confirm it exists. I’ve created an issue on GitHub. Please follow it for updates. Meanwhile, can you share for what reason you are using custom artifactsDir?

1 Like

Thanks @ylv-io for taking up the issue

Reason for using artifactsDir

The react app is not able to access files outside of app/src
So the json files need to be inside app/src
For this I set contracts_build_directory in truffle-config.js so that the jsons get created some place inside app/src/ and we do not need to manually copy paste them each time

We can not do it other way around as else the contract source code would become part of the app which we do not want.

2 Likes

Hi @vikram,

An alternative option could be to create a symlink so that the artifacts can be accessed from src. See the example in the guides:
https://docs.openzeppelin.com/learn/sending-gasless-transactions#creating-the-dapp

1 Like

It is true that React out of the box doesn’t allow you to access file out of React src folder.
You can remove ModuleScopePlugin from React Webpack plugins list in order to import files from anywhere.
I found it more preferable than building artifacts to React app. But that is a matter of personal choice.

1 Like