这里有两个相互依赖的函数
async function block() {
let getBlock = await web3.eth.getBlock('latest');
console.log(getBlock['number']);
let lblock = getBlock['number'] - 8;
console.log(lblock);
}
block();
pcsfactoryC.events.PairCreated({
fromBlock: lblock
})
使用async函数,我得到了最新的块,然后进行了一些计算,得到了变量lblock,我在下面的函数中使用它作为{fromBlock: lblock}
的输入
那么,如何在另一个函数中使用变量“lblock”呢?
2条答案
按热度按时间zmeyuzjn1#
Return it from the function.
Since
block()
isasync
, it returns a promise. You either have to useawait
to wait for it (you can only do this if the other function is alsoasync
, or use.then()
to execute a function when the promise is resolved.72qzrwbm2#
设函数abc(){ a=10 }
函数xyz(){ alert(a)}
abc()xyz()