![](/img/trans.png)
[英]How can I execute a script with environment variable and execute with truffle
[英]How to nest promises with truffle deployer in truffle migration script
我正在使用 truffle deployer 来部署我的solidity合约:
module.exports = function(deployer, network) {
...
}
我想在这个迁移过程中在链上存储一些数据。 通过使用 promise 回调参数并调用合约上的一些函数,数据的基本存储工作正常。 但我需要做一些更复杂的事情,如以下代码片段中所述:
deployer.deploy(A).then(instance => {
instance.addB(id, some params ...).then(result => {
// result is not the added B -> using getB() to load B
instance.getB(id).then(instanceB => {
instanceB.addC(id, some params ...);
})
});
})
问题是,内部函数没有正确执行。 instance.addB()
确实将 B 正确存储到链中。 但是 C 从未存储到链中,我不明白为什么。 此外,如果我将console.log('some text')
添加到内部 function 它不会打印到控制台。
有人知道如何解决这个问题吗?
使用“等待/异步”而不是 promise 回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.