To interact with your contracts stored on ethereum blockchain you need to instanciate them using web3js
You can create a file inside services folder with the name of your contract
// campaign-factory.ts
import {web3} from "./web3-instance";
import CampaignFactory from '../../contracts/CampaignFactory.json';
const CampaignFactoryContract = new web3.eth.Contract(CampaignFactory.abi, "0x791F9a9e9e7E6b7Ef6370bde6c364e80889f613F");
export default CampaignFactoryContract;
Sometimes you don’t know the address where the contract is deployed and want to pass it as a parameter
import {web3} from './web3-instance';
import Campaign from '../../contracts/Campaign.json';
// receives the address as a parameter then instanciate the contract
export default (address: string) => {
return new web3.eth.Contract(Campaign.abi, address);
};
import Campaign from './campaign';
CampaignContract: any;
CampaignFactoryContract :any;
constructor() {
this.web3js = web3;
this.CampaignFactoryContract = CampaignFactoryContract;
}
private instantiateCampaignContract(address: string) {
// call the method passing it the address as a parameter
this.CampaignContract = Campaign(address);
}