Version: 23.1.0
This documentation is for Taquito version 23.1.0 and is no longer being updated. Some information may be outdated. View the latest version .
Storage with/without annotations
Written by Roxane Letourneau
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.
When all the properties are annotated
//storage representation in Michelson
(pair
(pair
(pair (address %theAddress) (bool %theBool))
(pair (nat %theNat) (int %theNumber)))
(mutez %theTez))
We need to write the storage as a Javascript object and include the annotated names in it.
// const Tezos = new TezosToolkit('https://ghostnet.tezos.ecadinfra.com'); try { const originationOp = await Tezos.contract.originate({ code: contractStorageAnnot, storage: { theAddress: 'tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr', theBool: true, theNat: '3', theNumber: '5', theTez: '10', }, }); console.log(`Waiting for confirmation of origination for ${originationOp.contractAddress}...`); await originationOp.contract(); console.log(`Origination completed.`); } catch (error) { console.log(`Error: ${JSON.stringify(error, null, 2)}`); }
// const Tezos = new TezosToolkit('https://ghostnet.tezos.ecadinfra.com'); try { const originationOp = await Tezos.wallet .originate({ code: contractStorageAnnot, storage: { theAddress: 'tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr', theBool: true, theNat: '3', theNumber: '5', theTez: '10', }, }) .send(); console.log(`Waiting for confirmation of origination...`); await originationOp.contract(); console.log(`Origination completed.`); } catch (error) { console.log(`Error: ${JSON.stringify(error, null, 2)}`); }
When there is no annotation
//storage representation in Michelson
(pair
(pair
(pair (address) (bool))
(pair (nat) (int)))
(mutez))
All properties in storage are accessible by the index corresponding to the order that the storage is defined.
// const Tezos = new TezosToolkit('https://ghostnet.tezos.ecadinfra.com'); try { const originationOp = await Tezos.contract.originate({ code: contractStorageWithoutAnnot, storage: { 0: 'tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr', //address 1: true, //bool 2: '3', //nat 3: '5', //int 4: '10', //mutez }, }); console.log(`Waiting for confirmation of origination for ${originationOp.contractAddress}...`); await originationOp.contract(); console.log(`Origination completed.`); } catch (error) { console.log(`Error: ${JSON.stringify(error, null, 2)}`); }
// const Tezos = new TezosToolkit('https://ghostnet.tezos.ecadinfra.com'); try { const originationOp = await Tezos.wallet .originate({ code: contractStorageWithoutAnnot, storage: { 0: 'tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr', //address 1: true, //bool 2: '3', //nat 3: '5', //int 4: '10', //mutez }, }) .send(); console.log(`Waiting for confirmation of origination...`); await originationOp.contract(); console.log(`Origination completed.`); } catch (error) { console.log(`Error: ${JSON.stringify(error, null, 2)}`); }
When some arguments are annotated and others are not
//storage representation in Michelson
(pair
(pair
(pair (address) (bool))
(pair (nat %theNat) (int %theNumber)))
(mutez))
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.
// const Tezos = new TezosToolkit('https://ghostnet.tezos.ecadinfra.com'); try { const originationOp = await Tezos.contract.originate({ code: contractStorageWithAndWithoutAnnot, storage: { 0: 'tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr', //address 1: true, //bool theNat: '3', theNumber: '5', 4: '10', //mutez }, }); console.log(`Waiting for confirmation of origination for ${originationOp.contractAddress}...`); await originationOp.contract(); console.log(`Origination completed.`); } catch (error) { console.log(`Error: ${JSON.stringify(error, null, 2)}`); }
// const Tezos = new TezosToolkit('https://ghostnet.tezos.ecadinfra.com'); try { const originationOp = await Tezos.wallet .originate({ code: contractStorageWithAndWithoutAnnot, storage: { 0: 'tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr', //address 1: true, //bool theNat: '3', theNumber: '5', 4: '10', //mutez }, }) .send(); console.log(`Waiting for confirmation of origination...`); await originationOp.contract(); console.log(`Origination completed.`); } catch (error) { console.log(`Error: ${JSON.stringify(error, null, 2)}`); }