I am trying to use truffle-contract and web3 to create a new instance of a contract and then get the contract address of the contract that I just created.
I have tried the following code with a few similar variations but I get an error of the form "Cannot set property 'contractInstance' of undefined"
I understand it can take a few minutes to create the contract but how do I factor this into the code?
What is the recommended way to do this, or best practice?
createNewContract(value) {
return new Promise((resolve, reject) => {
const contract = require('@truffle/contract');
const transferContract = contract(tokenAbi);
transferContract.setProvider(that.web3);
transferContract.new({from: account}).then(function(instance) {
this.contractInstance = instance.address;
return instance.address;
}).then(function(status) {
if (status) {
return resolve({status: true});
}
}).catch(function(error) {
console.log(error);
return reject('new contract error');
});
});
}
Thanks