Storage with/without annotations This section shows how to write storage when :
it has annotations it has no annotation it has a mix of annotated and not-annotated properties To do so, let's look at three examples of contract origination showing initial values in the storage.
//storage representation in Michelson
(pair
(pair
(pair (address %theAddress) (bool %theBool))
(pair (nat %theNat) (int %theNumber)))
(mumav %theTez))
Copy We need to write the storage as a Javascript object and include the annotated names in it.
Tezos . contract
. originate ( {
code : contractStorageAnnot ,
storage : {
theAddress : 'mv1EQssQ7RPhKvocd4rhHsSA1BYGe5VKYeDo' ,
theBool : true ,
theNat : '3' ,
theNumber : '5' ,
theTez : '10' ,
} ,
} )
. then ( ( originationOp ) => {
println ( ` Waiting for confirmation of origination for ${ originationOp . contractAddress } ... ` ) ;
return originationOp . contract ( ) ;
} )
. then ( ( ) => {
println ( ` Origination completed. ` ) ;
} )
. catch ( ( error ) => println ( ` Error: ${ JSON . stringify ( error , null , 2 ) } ` ) ) ;
Copy
Tezos . wallet
. originate ( {
code : contractStorageAnnot ,
storage : {
theAddress : 'mv1EQssQ7RPhKvocd4rhHsSA1BYGe5VKYeDo' ,
theBool : true ,
theNat : '3' ,
theNumber : '5' ,
theTez : '10' ,
} ,
} )
. send ( )
. then ( ( originationOp ) => {
println ( ` Waiting for confirmation of origination... ` ) ;
return originationOp . contract ( ) ;
} )
. then ( ( ) => {
println ( ` Origination completed. ` ) ;
} )
. catch ( ( error ) => println ( ` Error: ${ JSON . stringify ( error , null , 2 ) } ` ) ) ;
Copy //storage representation in Michelson
(pair
(pair
(pair (address) (bool))
(pair (nat) (int)))
(mumav))
Copy All properties in storage are accessible by the index corresponding to the order that the storage is defined.
Tezos . contract
. originate ( {
code : contractStorageWithoutAnnot ,
storage : {
0 : 'mv1EQssQ7RPhKvocd4rhHsSA1BYGe5VKYeDo' ,
1 : true ,
2 : '3' ,
3 : '5' ,
4 : '10' ,
} ,
} )
. then ( ( originationOp ) => {
println ( ` Waiting for confirmation of origination for ${ originationOp . contractAddress } ... ` ) ;
return originationOp . contract ( ) ;
} )
. then ( ( ) => {
println ( ` Origination completed. ` ) ;
} )
. catch ( ( error ) => println ( ` Error: ${ JSON . stringify ( error , null , 2 ) } ` ) ) ;
Copy
Tezos . wallet
. originate ( {
code : contractStorageWithoutAnnot ,
storage : {
0 : 'mv1EQssQ7RPhKvocd4rhHsSA1BYGe5VKYeDo' ,
1 : true ,
2 : '3' ,
3 : '5' ,
4 : '10' ,
} ,
} )
. send ( )
. then ( ( originationOp ) => {
println ( ` Waiting for confirmation of origination... ` ) ;
return originationOp . contract ( ) ;
} )
. then ( ( ) => {
println ( ` Origination completed. ` ) ;
} )
. catch ( ( error ) => println ( ` Error: ${ JSON . stringify ( error , null , 2 ) } ` ) ) ;
Copy //storage representation in Michelson
(pair
(pair
(pair (address) (bool))
(pair (nat %theNat) (int %theNumber)))
(mumav))
Copy In the following example, only the elements in positions 2 and 3 have an annotation. We need to access these elements with their annotated name and the others with corresponding indexes.
Note that when proprieties have annotations, we cannot access them by index. For example, if you replace "theNat" by 2 and "theNumber" by 3 in this code example, it will fail.
Tezos . contract
. originate ( {
code : contractStorageWithAndWithoutAnnot ,
storage : {
0 : 'mv1EQssQ7RPhKvocd4rhHsSA1BYGe5VKYeDo' ,
1 : true ,
theNat : '3' ,
theNumber : '5' ,
4 : '10' ,
} ,
} )
. then ( ( originationOp ) => {
println ( ` Waiting for confirmation of origination for ${ originationOp . contractAddress } ... ` ) ;
return originationOp . contract ( ) ;
} )
. then ( ( ) => {
println ( ` Origination completed. ` ) ;
} )
. catch ( ( error ) => println ( ` Error: ${ JSON . stringify ( error , null , 2 ) } ` ) ) ;
Copy
Tezos . wallet
. originate ( {
code : contractStorageWithAndWithoutAnnot ,
storage : {
0 : 'mv1EQssQ7RPhKvocd4rhHsSA1BYGe5VKYeDo' ,
1 : true ,
theNat : '3' ,
theNumber : '5' ,
4 : '10' ,
} ,
} )
. send ( )
. then ( ( originationOp ) => {
println ( ` Waiting for confirmation of origination... ` ) ;
return originationOp . contract ( ) ;
} )
. then ( ( ) => {
println ( ` Origination completed. ` ) ;
} )
. catch ( ( error ) => println ( ` Error: ${ JSON . stringify ( error , null , 2 ) } ` ) ) ;
Copy