@@ -33,11 +33,11 @@ const listener = new ChiaBlockListener()
3333// Listen for block events
3434listener .on (' blockReceived' , (block ) => {
3535 console .log (` New block received: ${ block .height } ` )
36- console .log (` Header hash: ${ block .headerHash } ` )
36+ console .log (` Header hash: ${ block .header_hash } ` )
3737 console .log (` Timestamp: ${ new Date (block .timestamp * 1000 )} ` )
38- console .log (` Coin additions: ${ block .coinAdditions .length } ` )
39- console .log (` Coin removals: ${ block .coinRemovals .length } ` )
40- console .log (` Coin spends: ${ block .coinSpends .length } ` )
38+ console .log (` Coin additions: ${ block .coin_additions .length } ` )
39+ console .log (` Coin removals: ${ block .coin_removals .length } ` )
40+ console .log (` Coin spends: ${ block .coin_spends .length } ` )
4141})
4242
4343// Listen for peer connection events
@@ -155,11 +155,11 @@ Fired when a peer connection is lost.
155155
156156``` typescript
157157interface BlockReceivedEvent {
158- peerId: string // ID of the peer that sent this block
159- height: number // Block height
160- weight: string // Block weight as string
158+ peerId: string // IP address of the peer that sent this block
159+ height: number // Block height
160+ weight: string // Block weight as string
161161 headerHash: string // Block header hash (hex)
162- timestamp: number // Block timestamp (Unix time)
162+ timestamp: number // Block timestamp (Unix time)
163163 coinAdditions: CoinRecord [] // New coins created in this block
164164 coinRemovals: CoinRecord [] // Coins spent in this block
165165 coinSpends: CoinSpend [] // Detailed spend information
@@ -173,17 +173,17 @@ interface BlockReceivedEvent {
173173
174174``` typescript
175175interface PeerConnectedEvent {
176- peerId: string // Unique peer identifier
177- host: string // Peer hostname/IP
178- port: number // Peer port number
176+ peerId: string // Peer IP address
177+ host: string // Peer hostname/IP
178+ port: number // Peer port number
179179}
180180```
181181
182182#### ` PeerDisconnectedEvent `
183183
184184``` typescript
185185interface PeerDisconnectedEvent {
186- peerId: string // Unique peer identifier
186+ peerId: string // Peer IP address
187187 host: string // Peer hostname/IP
188188 port: number // Peer port number
189189 message? : string // Optional disconnection reason
@@ -195,21 +195,19 @@ interface PeerDisconnectedEvent {
195195``` typescript
196196interface CoinRecord {
197197 parentCoinInfo: string // Parent coin ID (hex)
198- puzzleHash: string // Puzzle hash (hex)
199- amount: string // Coin amount as string
198+ puzzleHash: string // Puzzle hash (hex)
199+ amount: string // Coin amount as string
200200}
201201```
202202
203203#### ` CoinSpend `
204204
205205``` typescript
206206interface CoinSpend {
207- coin: CoinRecord // The coin being spent
207+ coin: CoinRecord // The coin being spent
208208 puzzleReveal: string // CLVM puzzle bytecode (hex)
209- solution: string // CLVM solution bytecode (hex)
210- realData: boolean // Whether this is real spend data
211- parsingMethod: string // Method used to parse the spend
212- offset: number // Offset in the generator bytecode
209+ solution: string // CLVM solution bytecode (hex)
210+ offset: number // Offset in the generator bytecode
213211}
214212```
215213
@@ -238,14 +236,14 @@ listener.on('blockReceived', (block: BlockReceivedEvent) => {
238236 console .log (` Block ${block .height } from peer ${block .peerId } ` )
239237
240238 // Process coin additions
241- block .coinAdditions .forEach ((coin : CoinRecord ) => {
239+ block .coin_additions .forEach ((coin : CoinRecord ) => {
242240 console .log (` New coin: ${coin .amount } mojos ` )
243241 })
244242
245243 // Process coin spends
246- block .coinSpends .forEach ((spend : CoinSpend ) => {
244+ block .coin_spends .forEach ((spend : CoinSpend ) => {
247245 console .log (` Spend: ${spend .coin .amount } mojos ` )
248- console .log (` Puzzle: ${spend .puzzleReveal } ` )
246+ console .log (` Puzzle: ${spend .puzzle_reveal } ` )
249247 console .log (` Solution: ${spend .solution } ` )
250248 })
251249})
@@ -269,7 +267,7 @@ const testnetPeer = listener.addPeer('testnet-node.chia.net', 58444, 'testnet')
269267async function getHistoricalBlocks() {
270268 try {
271269 const block = listener .getBlockByHeight (mainnetPeer , 1000000 )
272- console .log (` Block 1000000 hash: ${block .headerHash } ` )
270+ console .log (` Block 1000000 hash: ${block .header_hash } ` )
273271
274272 const blocks = listener .getBlocksRange (mainnetPeer , 1000000 , 1000010 )
275273 console .log (` Retrieved ${blocks .length } blocks ` )
@@ -292,8 +290,8 @@ console.log('Available events:', eventTypes)
292290listener .on (' blockReceived' , (block ) => {
293291 const targetPuzzleHash = ' 0x1234...' // Your puzzle hash
294292
295- block .coinSpends .forEach ((spend ) => {
296- if (spend .coin .puzzleHash === targetPuzzleHash) {
293+ block .coin_spends .forEach ((spend ) => {
294+ if (spend .coin .puzzle_hash === targetPuzzleHash) {
297295 console .log (' Found spend for our puzzle!' )
298296 console .log (' Amount:' , spend .coin .amount )
299297 console .log (' Solution:' , spend .solution )
0 commit comments