我正在调用以下函数:
test: function()
{
alert("test1");
let meta
LoyaltyCard.deployed().then(function (instance) {
meta = instance
alert("test");
}).catch(function (e) {
alert(e);
})
//})
}
,并按如下方式调用它:
<button type="button" onclick="App.test()">TEST</button>
不幸的是,调用此部分时:
}).catch(function (e) {
alert(e);
我得到以下信息:
错误:LoyaltyCard尚未部署到检测到的网络 (网络/工件不匹配)
有人知道为什么吗?
答案 0 :(得分:0)
与Web3库进行交互时,必须使用await和async。以下是我使用角度6获取部署合同实例的示例。
async getInstance() {
await this.web3Service.artifactsToContract(artifacts)
.then((uLoanAbstraction) => {
this.LoanAbstraction = uLoanAbstraction;
});
this.deployedLoans = await this.uLoanAbstraction.deployed();
// Later in the app i use this.deployedLoans to interact with the smart contract
}