Skip to content

Instantly share code, notes, and snippets.

@m-kus
Last active September 11, 2019 13:52
Show Gist options
  • Save m-kus/e1aeea77ae9ecadcd166ed9bf843fff8 to your computer and use it in GitHub Desktop.
Save m-kus/e1aeea77ae9ecadcd166ed9bf843fff8 to your computer and use it in GitHub Desktop.
Encoding initial storage for a Michelson smart contract
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from pytezos import pytezos"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"ci = pytezos.contract('KT1Lx7XAYhySGVGG9MBFcDQo7Cxg4kDBido9')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ci.contract.storage.default()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<pytezos.michelson.contract.ContractStorage object at 0x7f51e61f91d0>\n",
"\n",
"$storage:\n",
"\t{ $address : [ string , $nat , { $nat : [ $timestamp , $mutez ] , ... } ] , ... }\n",
"\n",
"$address:\n",
"\tstring /* Base58 encoded `tz` or `KT` address */\n",
"\n",
"$mutez:\n",
"\tint /* Amount in `utz` (10^-6) */ ||\n",
"\tDecimal /* Amount in `tz` */\n",
"\n",
"$nat:\n",
"\tint /* Natural number */\n",
"\n",
"$timestamp:\n",
"\tint /* Unix time in seconds */ ||\n",
"\tstring /* Formatted datetime `%Y-%m-%dT%H:%M:%SZ` */\n",
"\n",
"\n",
"Helpers\n",
".big_map_decode()\n",
".big_map_diff_decode()\n",
".big_map_diff_encode()\n",
".big_map_query()\n",
".decode()\n",
".default()\n",
".encode()"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ci.contract.storage"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'prim': 'Elt',\n",
" 'args': [{'string': 'tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm'},\n",
" {'prim': 'Pair',\n",
" 'args': [{'prim': 'Pair', 'args': [{'string': 'Misha'}, {'int': '0'}]},\n",
" []]}]}]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ci.contract.storage.encode({\n",
" 'tz1grSQDByRpnVs7sPtaprNZRp531ZKz6Jmm': [\n",
" 'Misha',\n",
" 0,\n",
" {}\n",
" ]\n",
"})"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment