0

Is there a way to automatically create a new Solidity Contract - from within a web3 JS file using the .json file created in a project's build folder after each compile?

I have already figured out how to READ the .json file from the project's build folder using this snippet:

const contractJSONABI = await $.getJSON("MyContract.json", function (data) {
  console.log(JSON.stringify(data, undefined, 2));
});

But what I'm missing now is how do I actually use this ABI data to programmatically create a contract instance using web3.js? Like one I can actually call functions from?

I've been trying the following and its not quite working (I'm on web3 v. 0.20.3):

  MyApp.myContract = MyApp.web3Object.eth.contract(MyApp.contractJSONABI);
  MyApp.myContractInstance = MyApp.myContract.at(MyApp.contractAddress);

Would appreciate any help!

Your Answer

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

Browse other questions tagged or ask your own question.