0

When we write scripts for executing the functions of smart contracts we can use "artifacts.require()" in those vanilla javascript files. But If we use it in react.js files it gives an error telling that "artifacts" is not defined. So why is it happening? why can't we use "artifacts.require()" in react.js files even though we can use it in vanilla js files?

1 Answer 1

0

you can use in truffle

 artifacts.require()

because in truffle.config.js, you already told truffle where to look for those artifacts. Artifacts are JSON files of the contracts.

// truffle.config.js
module.exports = {
  // truffle reads from here
  contracts_directory: "./src/contracts",
  contracts_build_directory: "./src/abis",
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*",
    },
  },
  compilers: {
    solc: {
      version: "0.8.4",
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },
};
2
  • but if we use vanilla js we can use "artifacts.require()". problem occurs when it comes to react. Is there any clarification to that?
    – Jagath
    Dec 30, 2021 at 8:03
  • @Jagath vanilla.js files are located inside truffle directories. if u get a .js file outside truffle directories and use artifacts, you will get errror,as well
    – Yilmaz
    Dec 30, 2021 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.