Created
April 12, 2022 00:11
-
-
Save KenoLeon/5bbc83f9243821d6b226dc840b9e0b7b to your computer and use it in GitHub Desktop.
INfura promise example full
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
| const { ethers } = require("ethers"); | |
| async function main() { | |
| // Configure the ITX provider using your Infura credentials | |
| const itx = new ethers.providers.InfuraProvider( | |
| process.env.ETHEREUM_NETWORK, | |
| process.env.INFURA_PROJECT_ID | |
| ); | |
| // Create a signer instance based on your private key | |
| const signer = new ethers.Wallet(process.env.SIGNER_PRIVATE_KEY, itx); | |
| console.log(`Signer public address: ${signer.address}`); | |
| // Send Ether to the ITX deposit contract | |
| // ITX will register the deposit after 10 confirmations | |
| // and credit the gas tank associated with your signer address | |
| // you can view your balance at any time by calling relay_getBalance | |
| const depositTx = await signer.sendTransaction({ | |
| // Address of the ITX deposit contract | |
| to: "0x015C7C7A7D65bbdb117C573007219107BD7486f9", | |
| // The amount of ether you want to deposit in your ITX gas tank | |
| value: ethers.utils.parseUnits("0.1", "ether"), | |
| }); | |
| console.log("Mining deposit transaction..."); | |
| console.log( | |
| `https://${process.env.ETHEREUM_NETWORK}.etherscan.io/tx/${depositTx.hash}` | |
| ); | |
| // Waiting for the transaction to be mined | |
| const receipt = await depositTx.wait(); | |
| // The transaction is now on chain! | |
| console.log(`Mined in block ${receipt.blockNumber}`); | |
| } | |
| require("dotenv").config(); | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment