Created
January 9, 2020 05:47
-
-
Save jonathunne/a43ad6a78c09bdf1eb98e77fd2ee3a81 to your computer and use it in GitHub Desktop.
Send Eth Function - Node Red ethersjs
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
| // paste into the "function" node in node-red | |
| ethers = global.get('ethers'); | |
| let provider = ethers.getDefaultProvider(flow.get("network")); | |
| const deployerPK = flow.get("deployer_pk"); | |
| let wallet = new ethers.Wallet(deployerPK, provider); | |
| let amount = ethers.utils.parseEther('0.001'); | |
| let to = msg.payload.user.fields.Address; | |
| async function transfer() { | |
| let tx = { | |
| to: to, | |
| // ... or supports ENS names | |
| // to: \"ricmoo.firefly.eth\", | |
| value: amount | |
| }; | |
| let result = await wallet.sendTransaction(tx); | |
| sendPromise.then((tx) => { | |
| console.log(tx); | |
| { | |
| // All transaction fields will be present | |
| "nonce", "gasLimit", "gasPrice", "to", "value", "data", | |
| "from", "has", "r", "s", "v" | |
| } | |
| }); | |
| msg.payload = result; | |
| node.send(msg); | |
| node.done(); | |
| } | |
| transfer(); | |
| return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment