I've been meaning to put together a short how-to about getting setup with armoryengine, which is the base of Armory. Anything Armory does, armoryengine can do. But it can be pain to setup in Windows, and some people need a little push with some example code to make it happen. So I'm going to explain how to get into the interactive environment in both Windows and Linux, then some sample code to see how you can access armoryengine.py functionality:
Setting up in Ubuntu: This is just five commands as posted on the
Building Armory from Source page. It works on a fresh boot Ubuntu, as long as you have an internet connection:
$ sudo apt-get install git-core build-essential pyqt4-dev-tools swig libqtcore4 libqt4-dev python-qt4 python-dev python-twisted python-psutil
$ git clone git://github.com/etotheipi/BitcoinArmory.git
$ cd BitcoinArmory
$ make
$ python
$ >>> from armoryengine import *
Now you have access to all armoryengine has to offer.
Setting up in Windows: Quite a bit more involved, because you need to install all the python dependencies manually, and install Armory itself to get a .dll you need (but which isn't bundled in the git repo). But I just tested this on a fresh Windows VM, so this should work reliably.
(1-7) Follow the Windows instructions on the
Building Armory from Source page,
but only through installing zope.interface. Stop once you get to the SWIG step (you don't need swig or anything else there)
(
Grab the latest
64-bit version of Armory. You need two files from it to run the python utilities.
(9) Copy _CppBlockUtils.pyd and CppBlockUtils.py from "C:\Program Files (x86)\Armory\Armory Bitcoin Client\" into your cloned git repo.
(10) Open "Git Bash" put on your desktop and "cd" your way to the git repo.
(11) Type "/c/Python27/python.exe"
(12) Type "from armoryengine import *"
Some simple things you can do with armoryengine.py:
Here's a simple script showing a bunch of things you can do. You can use it to play with addresses, transactions, binary strings, hex, binary, base58, etc.
from armoryengine import *
print 'Current time is: ', RightNow()
print 'Current time is: ', unixTimeToFormatStr(RightNow())
print 'Easy display of times and bytes: "%d"B is "%s"' % (10**7, bytesToHumanSize(10**7))
strBinary = '\x00\x00\x03\x0a'
strHex = binary_to_hex(strBinary)
print ''
print 'Original binary string in hex: ', strHex
print 'Switch endianness of a result: ', hex_switchEndian(strHex)
print 'Integer (little-endian is default):', hex_to_int(strHex)
print 'Integer (force big-endian): ', hex_to_int(strHex, BIGENDIAN)
print 'Convert numbers to hex or binary: ', int_to_hex(251)
print 'Convert numbers to hex or binary: ', int_to_hex(251, widthBytes=4)
print 'Convert numbers to hex or binary: ', int_to_hex(251, widthBytes=4, endOut=BIGENDIAN)
print ''
print 'Also convert Base58<-->Binary: ', binary_to_base58(strBinary)
print 'Also convert Base58<-->Binary: ', binary_to_hex(base58_to_binary('1ArmoryX'))
print 'Also convert Base58<-->Binary: ', binary_to_base58('\x00\x57\x60\xd5\xde\x82')
print ''
print 'Pack and unpack VAR_INTs: (158): ', binary_to_hex(packVarInt(158)[0])
print 'Pack and unpack VAR_INTs: (1883): ', binary_to_hex(packVarInt(1883)[0])
print 'Pack and unpack VAR_INTs: (2^53): ', unpackVarInt('\xfd\x5b\x07')
print 'Pack and unpack VAR_INTs: (2^53): ', binary_to_hex(packVarInt(2**53)[0])
print ''
print 'Make sure to only has binary strings, never hex! Always returns binary!'
print 'sha256(strHex): ', binary_to_hex( sha256(strBinary) )
print 'sha256(sha256(strHex)): ', binary_to_hex( hash256(strBinary) )
print 'ripemd160(sha256(strHex)): ', binary_to_hex( hash160(strBinary) )
print ''
print 'Play with transactions:'
txHex = ('01000000012cd3dbb674a379211607838af7caa165f36f5823367208c51fc1a0'
'344e96a3f1010000008b483045022100d857839cd7f2da84c8993f4c72afbe07'
'4a5c77a44b2b43b1f8df4601df71e54602207a2647d11c7bafa03345dd41298e'
'2d5b54f524fcbe846dd8114ed1ed7cc2d34e0141043753f29064339c7f616b3e'
'baa27873be06bde832a603f014421f6270de0371aed18bf82ac65ec26eef758e'
'452fd30dee1d43d34d452b030ccbb8bc777664e6d5ffffffff0200e1f5050000'
'00001976a91416b31981c5aed9fcb85c863b9f808638a8bab72288ac806e5a43'
'000000001976a914ac4e0288884f2ca6866ccd5085c3e6e85c53bbf788ac0000'
'0000')
print 'View large blocks of hex conveniently (a full tx):',
print prettyHex(txHex)
tx = PyTx().unserialize( hex_to_binary( txHex ))
tx.pprint()
print 'Printing all inputs:'
for txin in tx.inputs:
txin.pprint()
print 'Printing all outputs:'
for txout in tx.outputs:
txout.pprint()
print ''
print 'Play with addresses: (note private and public keys are SecureBinaryData objects)'
privKey = SecureBinaryData('\xfa\xb3\x00\x39'*8)
addr = PyBtcAddress().createFromPlainKeyData(privKey)
print 'FullPrivKey:', binary_to_hex(addr.binPrivKey32_Plain.toBinStr())
print 'FullPubKey: ', binary_to_hex(addr.binPublicKey65.toBinStr())
print 'Hash160: ', binary_to_hex(addr.getAddr160())
print 'AddrStr: ', addr.getAddrStr()
The output of this script is:
Current time is: 1367089117.34
Current time is: 2013-Apr-27 02:58pm
Easy display of times and bytes: "10000000"B is "9.5 MB"
Original binary string in hex: 0000030a
Switch endianness of a result: 0a030000
Integer (little-endian is default): 167968768
Integer (force big-endian): 778
Convert numbers to hex or binary: fb
Convert numbers to hex or binary: fb000000
Convert numbers to hex or binary: 000000fb
Also convert Base58<-->Binary: 11ER
Also convert Base58<-->Binary: 005760d5de82
Also convert Base58<-->Binary: 1ArmoryX
Pack and unpack VAR_INTs: (158): 9e
Pack and unpack VAR_INTs: (1883): fd5b07
Pack and unpack VAR_INTs: (2^53): [1883, 3]
Pack and unpack VAR_INTs: (2^53): ff0000000000002000
Make sure to only has binary strings, never hex! Always returns binary!
sha256(strHex): 666945b30a69280a62d9c5215ff1417edb86c538669b497f62c35d2e66b388f3
sha256(sha256(strHex)): df4279ed267b3541eb5dcbb328219d3d409e6e1d22256ddf5b0ea2fb608ea47c
ripemd160(sha256(strHex)): 57e4edbd695ca33612537f4a62fde541bd65a1f3
Play with transactions:
View large blocks of hex conveniently (a full tx):
0x0000: 01000000 012cd3db b674a379 21160783 8af7caa1 65f36f58 23367208 c51fc1a0
0x0020: 344e96a3 f1010000 008b4830 45022100 d857839c d7f2da84 c8993f4c 72afbe07
0x0040: 4a5c77a4 4b2b43b1 f8df4601 df71e546 02207a26 47d11c7b afa03345 dd41298e
0x0060: 2d5b54f5 24fcbe84 6dd8114e d1ed7cc2 d34e0141 043753f2 9064339c 7f616b3e
0x0080: baa27873 be06bde8 32a603f0 14421f62 70de0371 aed18bf8 2ac65ec2 6eef758e
0x00a0: 452fd30d ee1d43d3 4d452b03 0ccbb8bc 777664e6 d5ffffff ff0200e1 f5050000
0x00c0: 00001976 a91416b3 1981c5ae d9fcb85c 863b9f80 8638a8ba b72288ac 806e5a43
0x00e0: 00000000 1976a914 ac4e0288 884f2ca6 866ccd50 85c3e6e8 5c53bbf7 88ac0000
0x0100: 0000
Transaction:
TxHash: d33a63e76e6ccb4783a1c843191ce3c317df8a0390eee4a91405802b1ab7dd00 (BE)
Version: 1
nInputs: 1
nOutputs: 2
LockTime: 0
Inputs:
PyTxIn:
PrevTxHash: f1a3964e34a0c11fc508723623586ff365a1caf78a8307162179a374b6dbd32c (BE)
TxOutIndex: 1
Script: (483045022100d857839cd7f2da84c8993f4c72afbe074a5c77a44b2b43b1f8df)
Sender: 1Gi4gDcPbUU2RiET5dNgZFVdj1Zyw3pdyM
Seq: 4294967295
Outputs:
TxOut:
Value: 100000000 ( 1.0 )
Script: OP_DUP OP_HASH (1352RHJqxaY8zF6S41drgYSqHNqYXJsYMq) OP_EQUAL OP_CHECKSIG
TxOut:
Value: 1130000000 ( 11.3 )
Script: OP_DUP OP_HASH (1Gi4gDcPbUU2RiET5dNgZFVdj1Zyw3pdyM) OP_EQUAL OP_CHECKSIG
Printing all inputs:
PyTxIn:
PrevTxHash: f1a3964e34a0c11fc508723623586ff365a1caf78a8307162179a374b6dbd32c (BE)
TxOutIndex: 1
Script: (483045022100d857839cd7f2da84c8993f4c72afbe074a5c77a44b2b43b1f8df)
Sender: 1Gi4gDcPbUU2RiET5dNgZFVdj1Zyw3pdyM
Seq: 4294967295
Printing all outputs:
TxOut:
Value: 100000000 ( 1.0 )
Script: OP_DUP OP_HASH (1352RHJqxaY8zF6S41drgYSqHNqYXJsYMq) OP_EQUAL OP_CHECKSIG
TxOut:
Value: 1130000000 ( 11.3 )
Script: OP_DUP OP_HASH (1Gi4gDcPbUU2RiET5dNgZFVdj1Zyw3pdyM) OP_EQUAL OP_CHECKSIG
Play with addresses: (note private and public keys are SecureBinaryData objects)
FullPrivKey: fab30039fab30039fab30039fab30039fab30039fab30039fab30039fab30039
FullPubKey: 04b5bdd137eb8001c3478402b04e2a5536af8511aa9e40c2c058e6af6470181130e28deff4fc5e9689f95e10410657c89dad9a5bbae4f5a081d6185a796d5b2600
Hash160: 12788165043cbd1bb914ae4c74f400531c5101d6
AddrStr: 12gfXKTYd1gqmyJCg7Sj36GQyt8KGuVsEz