Last active
April 12, 2022 18:44
-
-
Save KenoLeon/bf5a96bf27f2468bf26084ef1b95dc07 to your computer and use it in GitHub Desktop.
multi promise chain async functions await
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function callContract(contractAddress) { | |
| return new Promise((resolve) => { | |
| console.log(`Calling Contract with Address ${contractAddress}`) | |
| setTimeout(() => { | |
| resolve({ | |
| contractAddress: contractAddress, | |
| balance: '10 ETH' | |
| }); | |
| }, 1000); | |
| }) | |
| } | |
| function sendETH(contractResponse) { | |
| return new Promise((resolve) => { | |
| console.log(`Sending ${contractResponse.balance} to Keno's Contract`) | |
| setTimeout(() => { | |
| resolve({ | |
| txHash: '0x0....000008' | |
| }); | |
| }, 1000); | |
| }) | |
| } | |
| async function callContractTransferETH(Address) { | |
| const contractResponse = await callContract(Address); | |
| const txHash = await sendETH(contractResponse); | |
| console.log('Your Ticket is: ', txHash); | |
| } | |
| callContractTransferETH('0x0') | |
| // Should give you: | |
| // Calling Contract with Address 0x0 | |
| // Sending 10 ETH to Keno's Contract | |
| // Your Ticket is: { txHash: '0x0....000008' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment