-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathevm.js
40 lines (33 loc) · 1.31 KB
/
evm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const { ethers } = require("ethers");
const faucets = require('./contracts/faucets.json');
const contractAbi = require('./contracts/abi/faucet.json');
const tokens = require('./contracts/tokens.json');
async function requestFunds(token, address) {
// console.log('token, address:', token, address);
const provider = new ethers.providers.JsonRpcProvider(process.env.SHIMMEREVM_JSONRPC);
let contractAddress = faucets[token.toString()].address;
console.log('contractAddress:', contractAddress);
// console.log('contractAbi:', contractAbi);
const faucetContract = new ethers.Contract(contractAddress, contractAbi);
let wallet = await new ethers.Wallet(process.env.PRIVATE_KEY);
let walletSigner = await wallet.connect(provider);
const faucetSigner = faucetContract.connect(walletSigner);
let tx = await faucetSigner.requestFunds(address);
console.log('tx:', tx);
let txReceipt = await tx.wait();
console.log('txReceipt:', txReceipt);
return true;
}
async function getTokenData(token) {
return {
address: tokens[token.toString()].address,
symbol: token,
decimals: tokens[token.toString()].decimals,
image: 'https://files.iota.org/media/smr_evm_circular_crop.png'
};
}
module.exports = {
requestFunds,
getTokenData
};