-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathwallet.js
More file actions
27 lines (21 loc) · 855 Bytes
/
wallet.js
File metadata and controls
27 lines (21 loc) · 855 Bytes
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
export const signMessage = (provider, address) => {
if (!provider) return Promise.reject('No provider available')
console.log("provider", provider.signMessage)
return provider.signMessage({
message: 'Hello from AppKit!',
address: address
})
}
export const getBalance = async (provider, address) => {
if (!provider) return Promise.reject('No provider available')
// get the utxos ... this is the list of unspent transactions that the sender has
const utxos = await getUTXOs(address, false)
// return the sum of the utxos ... The balance of the sender
return utxos.reduce((sum, utxo) => sum + utxo.value, 0)
}
const getUTXOs = async (address) => {
const response = await fetch(
`https://mempool.space/api/address/${address}/utxo`
)
return await response.json();
}