-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.js
More file actions
54 lines (46 loc) · 1.88 KB
/
utils.js
File metadata and controls
54 lines (46 loc) · 1.88 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import axios from "axios"
export async function requestFaucet(address, endpoint = "https://testnet.archethic.net") {
return new Promise(async function (resolve, reject) {
try {
const faucetLink = `${endpoint}/faucet`
let response = await axios.get(faucetLink, {
headers: {
Origin: endpoint,
Referer: faucetLink,
Cookie: "_archethic_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYbUdHbWRVQWVvV1ZIcGtMazhxX0VmdG56.1_OFPYLSwLdkA7SnZNa7A5buhBL08fh6PaZRqu7SGh0"
}
})
const matches = response.data.match(/(?<=name="_csrf_token" value=").*?(?=">)/)
const csrf_token = matches[0]
const params = new URLSearchParams()
params.append('_csrf_token', csrf_token)
params.append('address', address)
response = await axios.post(`${endpoint}/faucet`, params, {
headers: {
Origin: endpoint,
Referer: faucetLink,
Cookie: "_archethic_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYbUdHbWRVQWVvV1ZIcGtMazhxX0VmdG56.1_OFPYLSwLdkA7SnZNa7A5buhBL08fh6PaZRqu7SGh0",
"Content-Type": "application/x-www-form-urlencoded"
}
})
if (!response.data.match(/Transaction submitted/)) {
reject("Unable to send the transaction")
return
} else {
resolve()
return
}
}
catch (e) {
reject(e)
return
}
})
}
export async function findTokenBalance(archethic, address, tokenAddress) {
const balance = await archethic.network.getBalance(address)
const tokenBalance = balance.token.find(x => {
return x.address == tokenAddress
})
return tokenBalance
}