Storing chains in database