Prepare View Contracts

Querying FA1.2.1

Instead of providing contract parameters in raw Michelson, we can use lorentz-contract-param to generate them.

The general invocation is:

lorentz-contract-param [Contract Name] [Contract Parameter Arguments]

To ensure it's properly installed, run:

$ which lorentz-contract-param
/usr/local/bin/lorentz-contract-param

Views

When a contract parameter has a non-unit return type, e.g. Get Total Supply, which returns the total supply of tokens, the contract needs to be able to store the result somewhere. In particular, another contract accepting the return value.

For the following examples, we need contracts accepting address and nat values:

$ alpha-client --wait none originate contract nat_storage transferring 0 \
from $ALICE_ADDRESS running "$(lorentz-contract print --name NatStorageContract)" \
--init 0 --burn-cap 0.295
Waiting for the node to be bootstrapped before injection...
Current head: BM8KmefAFDYs (timestamp: 2019-10-21T20:41:54-00:00, validation: 2019-10-21T20:42:37-00:00)
Node is bootstrapped, ready for injecting operations.
Estimated gas: 10909 units (will add 100 for safety)
Estimated storage: 295 bytes added (will add 20 for safety)
Operation successfully injected in the node.
Operation hash is 'onrbx5Mi4zFGwZhMiev8PAnRcRZmJj41YyTVEotDq1TphseAq7K'
NOT waiting for the operation to be included.
Use command
tezos-client wait for onrbx5Mi4zFGwZhMiev8PAnRcRZmJj41YyTVEotDq1TphseAq7K to be included --confirmations 30 --branch BM8KmefAFDYsmzDGTNavPoxJDcx9r1GTU8Nsj75isKNSAg6W6rp
and/or an external block explorer to make sure that it has been included.
This sequence of operations was run:
Manager signed operations:
From: tz1VhNvW3aWCHRNawF4sHfBfJAu5WrpcEbSQ
Fee to the baker:0.001367
Expected counter: 2034
Gas limit: 11009
Storage limit: 315 bytes
Balance updates:
tz1VhNvW3aWCHRNawF4sHfBfJAu5WrpcEbSQ ............ -0.001367
fees(tz1Ke2h7sDdakHJQh8WX4Z372du1KChsksyU,23) ... +0.001367
Origination:
From: tz1VhNvW3aWCHRNawF4sHfBfJAu5WrpcEbSQ
Credit:0
Script:
{ parameter nat ; storage nat ; code { CAR ; NIL operation ; PAIR } }
Initial storage: 0
No delegate for this contract
This origination was successfully applied
Originated contracts:
KT1TEXAiui2k9wdZgLr8Bx7oDUmXWSTf5sG7
Storage size: 38 bytes
Paid storage size diff: 38 bytes
Consumed gas: 10909
Balance updates:
tz1VhNvW3aWCHRNawF4sHfBfJAu5WrpcEbSQ ... -0.038
tz1VhNvW3aWCHRNawF4sHfBfJAu5WrpcEbSQ ... -0.257
New contract KT1TEXAiui2k9wdZgLr8Bx7oDUmXWSTf5sG7 originated.
Contract memorized as nat_storage3.
$ alpha-client --wait none originate contract address_storage transferring 0 \
from $ALICE_ADDRESS running "$(lorentz-contract print --name AddressStorageContract)" \
--init "\"$FA121_ADDRESS\"" --burn-cap 0.334
Waiting for the node to be bootstrapped before injection...
Current head: BL7vzTSk714H (timestamp: 2019-10-21T20:43:40-00:00, validation: 2019-10-21T20:43:49-00:00)
Node is bootstrapped, ready for injecting operations.
Estimated gas: 11314 units (will add 100 for safety)
Estimated storage: 320 bytes added (will add 20 for safety)
Operation successfully injected in the node.
Operation hash is 'ootVtQF6rs9NfmDaGh1bNGe8wk2qUXsSJR4mBoa5LXW4F77jNHT'
NOT waiting for the operation to be included.
Use command
tezos-client wait for ootVtQF6rs9NfmDaGh1bNGe8wk2qUXsSJR4mBoa5LXW4F77jNHT to be included --confirmations 30 --branch BL7vzTSk714HoNfSp7C8M3uAdAY5sN2VUhQgKmr1SxyDrGFKjzU
and/or an external block explorer to make sure that it has been included.
This sequence of operations was run:
Manager signed operations:
From: tz1VhNvW3aWCHRNawF4sHfBfJAu5WrpcEbSQ
Fee to the baker:0.001447
Expected counter: 2035
Gas limit: 11414
Storage limit: 340 bytes
Balance updates:
tz1VhNvW3aWCHRNawF4sHfBfJAu5WrpcEbSQ ............ -0.001447
fees(tz1Ke2h7sDdakHJQh8WX4Z372du1KChsksyU,23) ... +0.001447
Origination:
From: tz1VhNvW3aWCHRNawF4sHfBfJAu5WrpcEbSQ
Credit:0
Script:
{ parameter address ;
storage address ;
code { CAR ; NIL operation ; PAIR } }
Initial storage: "KT1XvNBJovT7XVedr29vw7QDWrqTU96NTQwR"
No delegate for this contract
This origination was successfully applied
Originated contracts:
KT1Kdd8aATDD2ckMTymZXYV5azyY76xfvarq
Storage size: 63 bytes
Paid storage size diff: 63 bytes
Consumed gas: 11314
Balance updates:
tz1VhNvW3aWCHRNawF4sHfBfJAu5WrpcEbSQ ... -0.063
tz1VhNvW3aWCHRNawF4sHfBfJAu5WrpcEbSQ ... -0.257
New contract KT1Kdd8aATDD2ckMTymZXYV5azyY76xfvarq originated.

Note: you may have to set/increase the burn cap to allow the contract(s) to be originated, e.g.:

$ alpha-client originate contract address_storage transferring 0 \
from $ALICE_ADDRESS running "$(lorentz-contract print --name AddressStorageContract)" \
--init "\"$FA121_ADDRESS\"" --burn-cap 0.0001 --dry-run
Waiting for the node to be bootstrapped before injection...
Current head: BLY4388F8VTU (timestamp: 2019-08-30T17:03:46-00:00, validation: 2019-08-30T17:04:08-00:00)
Node is bootstrapped, ready for injecting operations.
Fatal error:
The operation will burn ꜩ0.334 which is higher than the configured burn cap (0.0001).
Use `--burn-cap 0.334` to emit this operation.

Then, using alpha-client get receipt for [Operation hash] for each operation hash, store the contract addresses in variables:

NAT_STORAGE_ADDRESS="KT1.."
ADDRESS_STORAGE_ADDRESS="KT1.."

Next, you may access the stored values with the following two commands for nat and address, respectively:

$ alpha-client get contract storage for $NAT_STORAGE_ADDRESS
0
$ alpha-client get contract storage for $ADDRESS_STORAGE_ADDRESS
"KT1FSGT6B7FLGiVph6jj85xuSq3wCnj9pMAp"