Skip to content

Commit 3686970

Browse files
committed
add faucet
1 parent eb30e7c commit 3686970

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

faucet.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const { broadcast, waitForTx, setScript, invokeScript, nodeInteraction, transfer } = require("@waves/waves-transactions");
2+
const { address, base58Encode, base58Decode, publicKey, privateKey } = require("@waves/waves-crypto");
3+
const fetch = require('node-fetch');
4+
const env = process.env;
5+
if (env.NODE_ENV !== 'production') {
6+
require('dotenv').load();
7+
}
8+
9+
10+
let seed = env.MNEMONIC;
11+
const rpc = env.WAVES_RPC;
12+
const chainId = env.WAVES_CHAINID;
13+
14+
15+
const fauseed = "arm march lottery domain vibrant damp action crazy cloud humor increase sheriff"
16+
17+
18+
const fauscript = `
19+
{-# STDLIB_VERSION 3 #-}
20+
{-# CONTENT_TYPE DAPP #-}
21+
{-# SCRIPT_TYPE ACCOUNT #-}
22+
23+
@Verifier(tx)
24+
func verify() = {
25+
match (tx) {
26+
case o:TransferTransaction =>
27+
!isDefined(o.assetId) && o.fee <= 900000 && o.amount <= 10000000000 && sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
28+
case _ =>
29+
false
30+
}
31+
}
32+
`;
33+
34+
(async ()=> {
35+
36+
if ((process.argv.length==3) && (process.argv[2]=="deploy")) {
37+
let request = await fetch(`${env.WAVES_RPC}utils/script/compile`, { method: "POST", body: fauscript })
38+
const { script } = await request.json();
39+
let tx = setScript({ script, fee: 1400000, chainId}, fauseed);
40+
await broadcast(tx, rpc);
41+
await waitForTx(tx.id, { apiBase: rpc });
42+
43+
} else {
44+
const tx = transfer({
45+
fee:500000,
46+
amount:10000000000,
47+
recipient:address(seed, chainId)
48+
}, fauseed);
49+
await broadcast(tx, rpc);
50+
await waitForTx(tx.id, { apiBase: rpc });
51+
console.log(await nodeInteraction.balance(address(seed, chainId), rpc));
52+
}
53+
process.exit();
54+
})();

0 commit comments

Comments
 (0)