Transactions
程式碼範例:如何在發送交易之前獲取交易雜湊
我知道他們可能是網上的例子,但他們並沒有真正解決我的問題。
所以讓我們說我有下面的程式碼:
this.factoryContract = new ethers.Contract( "factoryContractAddress", "factoryContractABI", signer ); this.factoryContract.createChild()// how can I get transaction hash instead of waiting for it inside the "then(){}" callback? .then(()=>{/*do things here**/}); .catch(()=>{/*do things here**/});
我想我找到了你想要的但不確定。
async function creatChildContract(){ tx = await this.factoryContract.createChild(); tx.hash //returns hash of the transaction which user just signed. }
終於找到了我的問題的答案:
async function creatChildContract(){ this.factoryContract.createChild() .then((log)=>{ console.log(log.hash); // here you can access the transaction hash before it is mined // you do not have to wait, once the transaction is confirmed, the hash is available. }); .catch(()=>{/*do things here**/}) })