bitPony
nodejs module to parse and create data and net packages on bitcoin protocol and talk with nodes
Get started
var bitPony = ;
Types
Simple
//little Endian format (reverse byte order)console;//15console;//80 console;//61455console;//b988 console;//1114111console;//606d0000 console;//16711680console;//2**50 - 0000000000000400 console;//bitcoin is real moneyconsole;//626974636f696e206973207265616c206d6f6e6579
Bitcoin
//var int - special bitcoin type: https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer//fd - for uint16, fe - for uint32, ff 0 fir uint64, other - number. If first byte less than fd - its number uint8console;//16console;//fa console;//254console;//fd007d console;//25000console;//fda861 console;//2^50 1125899906842624console;//ff0000000000000400 //string - is var_str, special bitcoin type: https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_string//first byte - var_int length of string, next lenbytes - strconsole;//My name is Nanocatconsole; //hash - network byte order user. so, to make hash - need char32 with reversed bytesconsole;//00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048console;//4860eb18bf1b1620e37e9490fc8a427514416fd75159ab86688e9a8300000000
Complex types
tx input
//input from tx https://blockchain.info/ru/tx/70f4c44126d1924a28a2bcc297f9a79abfb85e688ecacb520468448312c89ef7?format=hex
{
hash: '612c0f25cda5ca7bcf6a3cad1a0a4c9c807b25e046ef939968b1c9d744791408',
index: 1,
scriptSig: '48304502...84b582b3fec',
script_len: 107,
sequence: 4294967295
}
console; //08147944d7c9b1689993ef46e0257b809c4c0a1aad3c6acf7bcaa5cd250f2c61010000006b483045022100e5dad2ab845fdabf02279fb424618547723790fd29937db738f11580facf8af20220763831cc67e7dad729bbf893da8f4ee2afbd81539314044e1b060ff664581de30121026aa1ae66d5a08776adafa2752b9d26c8b3202d261e9e83687c23b84b582b3fecffffffff console;//hash, index, scriptSig, sequence
tx out
//out from tx https://blockchain.info/ru/tx/8d4f4eb888a3130e31d1ac68045173e7a6b94a142843cde3c2fe74b64f3dd9da?format=hex
{
amount: 4046768,
scriptPubKey: 'a91481987422b78e406c48511c30b7962030e8b4e06f87',
script_len: 23
}
console; //b0bf3d000000000017a91481987422b78e406c48511c30b7962030e8b4e06f87console;
tx
{
version: 1,
in_count: 176,
in: [
{
hash: 'f83d0c94c1939037ec43e7231ee58bcbb05fa1ea9ac2e838cb3f340b85c931eb',
index: 67,
scriptSig: '47304402207fc2d....ba',
script_len: 138,
sequence: 4294967295
},
//....
]
out_count: 74,
out: [
{
amount: 237327,
scriptPubKey: 'a9148962c0b9c89965ef3056ecc38860222b7815a35787',
script_len: 23
},
//....
],
lock_time: 0,
hash: 'b0dfddb20b270e7a5355e1035124bae6d6667e11702f54fad56b164df98e16e0',
length: 28513
}
//https://blockchain.info/ru/tx/8d4f4eb888a3130e31d1ac68045173e7a6b94a142843cde3c2fe74b64f3dd9da?format=hexconsole //0100000001eb31...3578700000000console;
block header
//read first 81 byte from block: https://blockchain.info/block/00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048?format=hex
{
version: 1,
prev_block: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
merkle_root: '0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098',
timestamp: 1231469665,
bits: 486604799,
nonce: 2573394689,
txn_count: 1,
hash: '00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048'
}
console; //010000006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e3629900//80 bytes, without last var_int (tx count - 01) byteconsole;
block
//block parsing
//return:
/*
{
version: 536870914,
prev_block: '00000000000000000007126942a3353613c0a1793ac8d81bde244340d750f5e2',
merkle_root: 'a30181a9f15bef9c1c42635d853de139677ded5e3eb1af1c8f5ca8a857908157',
timestamp: 1503564603,
bits: 402734313,
nonce: 1728324334,
txn_count: 2614,
hash: '0000000000000000002f8bd6a1552596d822284e8fd3efa3fec200d548089cce'
}
2614
https;
User types
User can create own types on bitPony base, use function bitPony.extend.
More examples in wiki doc page
Contacts
You can write message about this project at my email: alex@letris.ru
Other language implementations
Java: https://github.com/alexshadie/bitpony-java
Donate
If my project help to you, you can donate me in bitcoin: 1KFhXAzjip6UCn8Lu8iuwvK4TkwLbmyN7e