I should click on a button in HTML such that by the clicking a smart contract must be deployed and its function must be run. But when i write the codes of the both operations in Node-js the followed error occurs:
`Error: This contract object doesn't have address set yet, please set an address first.`
By the followed code i deploy the contract and run its function. the contract's function is fill
.
app.post('/send-data', function(q,r){
var source2='E:/Alireza/contracts/customer.sol';
var customercompiled=solc.compile(source2)
var customerJson="E:/Alireza/build/contracts/customer.json";
var customerJs=JSON.parse(fs.readFileSync(customerJson));
var ByteCode="...";
var customer=new web3.eth.Contract(customerJs.abi, null, {data: ByteCode});
web3.eth.personal.unlockAccount("0x83Ad536099658519ee6A40A3faCAf3dDcEf6178a","Alireza").then(()=>{console.log("Address unlocked");}).catch(console.error);
customer.deploy().send({from: "0x6Db320B080b956c371c4bC5b00eF74e73bCE7798", gas:2100000, gasPrice:200}).then((instance)=>{console.log("Contract mined at "+instance.options.address);
customerInstance=instance}//Here, the contract is deployed.
customer.methods.fill(Arg1,Arg2).send({from: "0x6Db320B080b956c371c4bC5b00eF74e73bCE7798", gas:2000000, gasPrice:200});
//Above line is to interact with the contract and run its function called "fill".
);
How can i eliminate the mentioned error and improve the above code?