Bitcoin

Bitcoin Transfers

BitcoinTransfers Stream represents all possible native cryptocurrency transfers with positive (> 0) value

Details

1
{
2
address: address'btc',
3
currency: string,
4
amount: integer,
5
tx: {
6
id: string,
7
blockHash: string,
8
blockHeight: integer,
9
blocktime: integer,
10
confirmations: integer,
11
inputs: {
12
value: {
13
txId: string,
14
amount: integer,
15
n: integer,
16
addresses: list {
17
value: address'btc'
18
}
19
}
20
},
21
outputs: {
22
value: {
23
txId: string,
24
amount: integer,
25
n: integer,
26
addresses: list {
27
value: address'btc'
28
}
29
}
30
}
31
},
32
type: string
33
}
Copied!

Code Samples

This simple code will monitor every transfer on 1 address
1
stream BalanceChanges
2
from BitcoinTransfers
3
where @address == BTC.address("address")
4
process
5
emit { @address, @type, @amount }
6
end
Copied!
​
If you want to distinguish between transactions that are in mempool and in block (confirmed):
If you set @tx.confirmations to 2 or above, it will not work. Our platform can only see the first confirmation of a transaction
1
stream BitcoinMonitoring
2
from BitcoinTransfers
3
where @address == BTC.address("address")
4
process
5
​
6
if @tx.confirmations >= 1 then
7
emit {@type, @amount, @address, state: "in block"}
8
else
9
emit {@type, @amount, @address, state: "in mempool"}
10
end
11
12
end
Copied!
​
If you want to add current price of BTC, you need to use getRate function
1
stream BitcoinMonitoring
2
from BitcoinTransfers
3
where @address == BTC.address("address")
4
process
5
​
6
let currentPrice = getRate("BTC")
7
8
if @tx.confirmations >= 1 then
9
emit {@type, @amount, @address, state: "in block", currentPrice}
10
else
11
emit {@type, @amount, @address, state: "in mempool", currentPrice}
12
end
13
end
Copied!
Last modified 4d ago