diff --git a/libethereum/CommonData.h b/libethereum/CommonData.h
new file mode 100644
index 000000000..ca1fad1a6
--- /dev/null
+++ b/libethereum/CommonData.h
@@ -0,0 +1,186 @@
+/*
+ This file is part of cpp-ethereum.
+
+ cpp-ethereum is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ cpp-ethereum is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with cpp-ethereum. If not, see .
+*/
+/** @file Common.h
+ * @author Gav Wood
+ * @date 2014
+ *
+ * Shared algorithms and data types.
+ */
+
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+#include "Common.h"
+
+namespace eth
+{
+
+// String conversion functions, mainly to/from hex/nibble/byte representations.
+
+/// Convert a series of bytes to the corresponding string of hex duplets.
+/// @param _w specifies the width of each of the elements. Defaults to two - enough to represent a byte.
+/// @example toHex("A\x69") == "4169"
+template
+std::string toHex(_T const& _data, int _w = 2)
+{
+ std::ostringstream ret;
+ for (auto i: _data)
+ ret << std::hex << std::setfill('0') << std::setw(_w) << (int)(typename std::make_unsigned::type)i;
+ return ret.str();
+}
+
+/// Converts a (printable) ASCII hex character into the correspnding integer value.
+/// @example fromHex('A') == 10 && fromHex('f') == 15 && fromHex('5') == 5
+int fromHex(char _i);
+
+/// Converts a (printable) ASCII hex string into the corresponding byte stream.
+/// @example fromHex("41626261") == asBytes("Abba")
+bytes fromHex(std::string const& _s);
+
+/// Converts byte array to a string containing the same (binary) data. Unless
+/// the byte array happens to contain ASCII data, this won't be printable.
+inline std::string asString(bytes const& _b)
+{
+ return std::string((char const*)_b.data(), (char const*)(_b.data() + _b.size()));
+}
+
+/// Converts a string to a byte array containing the string's (byte) data.
+inline bytes asBytes(std::string const& _b)
+{
+ return bytes((byte const*)_b.data(), (byte const*)(_b.data() + _b.size()));
+}
+
+/// Converts a string into the big-endian base-16 stream of integers (NOT ASCII).
+/// @example asNibbles("A")[0] == 4 && asNibbles("A")[1] == 1
+bytes asNibbles(std::string const& _s);
+
+
+// Big-endian to/from host endian conversion functions.
+
+/// Converts a templated integer value to the big-endian byte-stream represented on a templated collection.
+/// The size of the collection object will be unchanged. If it is too small, it will not represent the
+/// value properly, if too big then the additional elements will be zeroed out.
+/// @a _Out will typically be either std::string or bytes.
+/// @a _T will typically by uint, u160, u256 or bigint.
+template
+inline void toBigEndian(_T _val, _Out& o_out)
+{
+ for (auto i = o_out.size(); i-- != 0; _val >>= 8)
+ o_out[i] = (typename _Out::value_type)(uint8_t)_val;
+}
+
+/// Converts a big-endian byte-stream represented on a templated collection to a templated integer value.
+/// @a _In will typically be either std::string or bytes.
+/// @a _T will typically by uint, u160, u256 or bigint.
+template
+inline _T fromBigEndian(_In const& _bytes)
+{
+ _T ret = 0;
+ for (auto i: _bytes)
+ ret = (ret << 8) | (byte)(typename std::make_unsigned::type)i;
+ return ret;
+}
+
+/// Convenience functions for toBigEndian
+inline std::string toBigEndianString(u256 _val) { std::string ret(32, '\0'); toBigEndian(_val, ret); return ret; }
+inline std::string toBigEndianString(u160 _val) { std::string ret(20, '\0'); toBigEndian(_val, ret); return ret; }
+inline bytes toBigEndian(u256 _val) { bytes ret(32); toBigEndian(_val, ret); return ret; }
+inline bytes toBigEndian(u160 _val) { bytes ret(20); toBigEndian(_val, ret); return ret; }
+
+/// Convenience function for toBigEndian.
+/// @returns a string just big enough to represent @a _val.
+template
+inline std::string toCompactBigEndianString(_T _val)
+{
+ int i = 0;
+ for (_T v = _val; v; ++i, v >>= 8) {}
+ std::string ret(i, '\0');
+ toBigEndian(_val, ret);
+ return ret;
+}
+
+
+// Algorithms for string and string-like collections.
+
+/// Escapes a string into the C-string representation.
+/// @p _all if true will escape all characters, not just the unprintable ones.
+std::string escaped(std::string const& _s, bool _all = true);
+
+/// Determines the length of the common prefix of the two collections given.
+/// @returns the number of elements both @a _t and @a _u share, in order, at the beginning.
+/// @example commonPrefix("Hello world!", "Hello, world!") == 5
+template
+uint commonPrefix(_T const& _t, _U const& _u)
+{
+ uint s = std::min(_t.size(), _u.size());
+ for (uint i = 0;; ++i)
+ if (i == s || _t[i] != _u[i])
+ return i;
+ return s;
+}
+
+/// Creates a random, printable, word.
+std::string randomWord();
+
+
+// General datatype convenience functions.
+
+/// Trims a given number of elements from the front of a collection.
+/// Only works for POD element types.
+template
+void trimFront(_T& _t, uint _elements)
+{
+ static_assert(std::is_pod::value, "");
+ memmove(_t.data(), _t.data() + _elements, (_t.size() - _elements) * sizeof(_t[0]));
+ _t.resize(_t.size() - _elements);
+}
+
+/// Pushes an element on to the front of a collection.
+/// Only works for POD element types.
+template
+void pushFront(_T& _t, _U _e)
+{
+ static_assert(std::is_pod::value, "");
+ _t.push_back(_e);
+ memmove(_t.data() + 1, _t.data(), (_t.size() - 1) * sizeof(_e));
+ _t[0] = _e;
+}
+
+/// Concatenate two vectors of elements. _T must be POD.
+template
+inline std::vector<_T>& operator+=(std::vector::value, _T>::type>& _a, std::vector<_T> const& _b)
+{
+ auto s = _a.size();
+ _a.resize(_a.size() + _b.size());
+ memcpy(_a.data() + s, _b.data(), _b.size() * sizeof(_T));
+ return _a;
+
+}
+
+/// Concatenate two vectors of elements. _T must be POD.
+template
+inline std::vector<_T> operator+(std::vector::value, _T>::type> const& _a, std::vector<_T> const& _b)
+{
+ std::vector<_T> ret(_a);
+ return ret += _b;
+}
+
+}
diff --git a/libethereum/CommonEth.h b/libethereum/CommonEth.h
new file mode 100644
index 000000000..1605f00f7
--- /dev/null
+++ b/libethereum/CommonEth.h
@@ -0,0 +1,137 @@
+/*
+ This file is part of cpp-ethereum.
+
+ cpp-ethereum is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ cpp-ethereum is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with cpp-ethereum. If not, see .
+*/
+/** @file CommonEth.h
+ * @author Gav Wood
+ * @date 2014
+ *
+ * Ethereum-specific data structures & algorithms.
+ */
+
+#pragma once
+
+#include "Common.h"
+#include "FixedHash.h"
+
+namespace eth
+{
+
+/// A secret key: 32 bytes.
+/// @NOTE This is not endian-specific; it's just a bunch of bytes.
+using Secret = h256;
+
+/// A public key: 64 bytes.
+/// @NOTE This is not endian-specific; it's just a bunch of bytes.
+using Public = h512;
+
+/// An Ethereum address: 20 bytes.
+/// @NOTE This is not endian-specific; it's just a bunch of bytes.
+using Address = h160;
+
+/// A vector of Ethereum addresses.
+using Addresses = h160s;
+
+/// User-friendly string representation of the amount _b in wei.
+std::string formatBalance(u256 _b);
+
+/// Get information concerning the currency denominations.
+std::vector> const& units();
+
+// The various denominations; here for ease of use where needed within code.
+static const u256 Uether = ((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000;
+static const u256 Vether = ((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000;
+static const u256 Dether = ((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000;
+static const u256 Nether = (((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000;
+static const u256 Yether = (((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000;
+static const u256 Zether = (((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000;
+static const u256 Eether = ((u256(1000000000) * 1000000000) * 1000000000) * 1000000000;
+static const u256 Pether = ((u256(1000000000) * 1000000000) * 1000000000) * 1000000;
+static const u256 Tether = ((u256(1000000000) * 1000000000) * 1000000000) * 1000;
+static const u256 Gether = (u256(1000000000) * 1000000000) * 1000000000;
+static const u256 Mether = (u256(1000000000) * 1000000000) * 1000000;
+static const u256 Kether = (u256(1000000000) * 1000000000) * 1000;
+static const u256 ether = u256(1000000000) * 1000000000;
+static const u256 finney = u256(1000000000) * 1000000;
+static const u256 szabo = u256(1000000000) * 1000;
+static const u256 Gwei = u256(1000000000);
+static const u256 Mwei = u256(1000000);
+static const u256 Kwei = u256(1000);
+static const u256 wei = u256(1);
+
+/// Convert a private key into the public key equivalent.
+/// @returns 0 if it's not a valid private key.
+Address toAddress(h256 _private);
+
+/// Simple class that represents a "key pair".
+/// All of the data of the class can be regenerated from the secret key (m_secret) alone.
+/// Actually stores a tuplet of secret, public and address (the right 160-bits of the public).
+class KeyPair
+{
+public:
+ /// Null constructor.
+ KeyPair() {}
+
+ /// Normal constructor - populates object from the given secret key.
+ KeyPair(Secret _k);
+
+ /// Create a new, randomly generated object.
+ static KeyPair create();
+
+ /// Retrieve the secret key.
+ Secret const& secret() const { return m_secret; }
+ /// Retrieve the secret key.
+ Secret const& sec() const { return m_secret; }
+
+ /// Retrieve the public key.
+ Public const& pub() const { return m_public; }
+
+ /// Retrieve the associated address of the public key.
+ Address const& address() const { return m_address; }
+
+private:
+ Secret m_secret;
+ Public m_public;
+ Address m_address;
+};
+
+
+// SHA-3 convenience routines.
+
+/// Calculate SHA3-256 hash of the given input and load it into the given output.
+void sha3(bytesConstRef _input, bytesRef _output);
+
+/// Calculate SHA3-256 hash of the given input, possibly interpreting it as nibbles, and return the hash as a string filled with binary data.
+std::string sha3(std::string const& _input, bool _isNibbles);
+
+/// Calculate SHA3-256 hash of the given input, returning as a byte array.
+bytes sha3Bytes(bytesConstRef _input);
+
+/// Calculate SHA3-256 hash of the given input (presented as a binary string), returning as a byte array.
+inline bytes sha3Bytes(std::string const& _input) { return sha3Bytes((std::string*)&_input); }
+
+/// Calculate SHA3-256 hash of the given input, returning as a byte array.
+inline bytes sha3Bytes(bytes const& _input) { return sha3Bytes((bytes*)&_input); }
+
+/// Calculate SHA3-256 hash of the given input, returning as a 256-bit hash.
+h256 sha3(bytesConstRef _input);
+
+/// Calculate SHA3-256 hash of the given input, returning as a 256-bit hash.
+inline h256 sha3(bytes const& _input) { return sha3(bytesConstRef((bytes*)&_input)); }
+
+/// Calculate SHA3-256 hash of the given input (presented as a binary-filled string), returning as a 256-bit hash.
+inline h256 sha3(std::string const& _input) { return sha3(bytesConstRef(_input)); }
+
+}
diff --git a/libethereum/CommonIO.h b/libethereum/CommonIO.h
new file mode 100644
index 000000000..a388fa8f9
--- /dev/null
+++ b/libethereum/CommonIO.h
@@ -0,0 +1,223 @@
+/*
+ This file is part of cpp-ethereum.
+
+ cpp-ethereum is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ cpp-ethereum is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with cpp-ethereum. If not, see .
+*/
+/** @file CommonIO.h
+ * @author Gav Wood
+ * @date 2014
+ *
+ * File & stream I/O routines.
+ */
+
+#pragma once
+
+#include