-
Notifications
You must be signed in to change notification settings - Fork 22
/
faucet_snippet.html
40 lines (33 loc) · 1.68 KB
/
faucet_snippet.html
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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://unpkg.com/web3@latest/dist/web3.min.js"></script>
</head>
<body>
<h1>Faucet snippet (select Rinkeby)</h1>
<pre id="log" style="width:100%;height:200px"></pre>
<script type="text/javascript">
function log(logstr) {
document.getElementById("log").innerHTML +=logstr+"\n";
}
async function f() {
web3 = new Web3(Web3.givenProvider); // provider from metamask
var acts=await web3.eth.requestAccounts().catch(x=>log(x.message));
const privateKey= '0x0da19552d21de3da01e4a5ff72f6722b9a86c78ee6c6a46e5cdcf0fb5a936110';
// note very insecure, but for test ETH this is usable
var addressFaucet = web3.eth.accounts.privateKeyToAccount(privateKey).address;
web3.eth.accounts.wallet.add(privateKey);
var fb=await web3.eth.getBalance(addressFaucet);
log(`Faucet has ${fb} on address ${addressFaucet}`);
log(`Wait about 20 seconds for transaction, note: no metamask confirm`);
result = await web3.eth.sendTransaction({from: addressFaucet,to: acts[0],gas: 200000,value: 1})
.catch(x => log(`Error: ${x.code} ${x.message}`));
log(`Transaction hash: ${result.transactionHash}`);
fb=await web3.eth.getBalance(addressFaucet);
log(`Faucet now has ${fb}`);
}
window.addEventListener('DOMContentLoaded', f);
</script>
</body>
</html>