0

I am attempting to deploy a very simple archetype contract with Taquito in a react Dapp. However, I am receiving a validation error. My guess is that I have the syntax wrong for the storage parameter, but I cannot figure out what it should be.

This error is being caught in this function:

const deployContract = async () => {
ttk.wallet.originate({
  code: testJSON,
  storage: {
    res: 0
  },
})
.send()
.then((originationOp) => {
  console.log(`Waiting for confirmation of origination...`);
  return originationOp.contract();
})
.then((contract) => {
  console.log(`Origination completed for ${contract.address}.`);
})
.catch((error) => console.log(`Error: ${JSON.stringify(error, null, 2)}`));
}

Where ttk is Tezos Toolkit and wallet is a beaconWallet. (This part of the code is copied from archetype docs)

I have the error:

Error: {
  "value": {
    "res": 0
  },
  "token": {
    "val": {
      "prim": "nat"
    },
    "idx": 0
  },
  "name": "NatValidationError",
  "message": "[0] Value is not a number: [object Object]"

The contract:

archetype simple

variable res : nat = 0

entry exec (n : nat) {
  res := n
}

The michelson/JSON input:

javascript
export const code = [
  { prim: 'storage', args: [{ prim: 'nat' }] },
  { prim: 'parameter', args: [{ prim: 'nat', annots: ['%exec'] }] },
  {
    prim: 'code',
    args: [
      [
        { prim: 'UNPAIR' },
        { prim: 'DUP' },
        {
          prim: 'DIP',
          args: [
            { int: '1' },
            [
              { prim: 'DIG', args: [{ int: '1' }] },
              { prim: 'DROP', args: [{ int: '1' }] },
            ],
          ],
        },
        { prim: 'DUG', args: [{ int: '1' }] },
        { prim: 'DROP', args: [{ int: '1' }] },
        { prim: 'NIL', args: [{ prim: 'operation' }] },
        { prim: 'PAIR' },
      ],
    ],
  },
]

I have tried inputing {"int" : "0"} in the storage and a few other less likely variations but I am now well and truly stuck

Any help is greatly appreciated.

-- EDIT --

The required syntax here is: storage: 0.

When a contract run through the archetype compiler has only a single nat in storage, the storage parameter to the originate method takes a single value.

When a contract run through the archetype archetype compiler has more than one item in storage, then the storage parameter takes an object. For example this contract...

archetype simple

variable res : nat = 0
variable ser: nat = 1

entry exec (n : nat) {
  res := n
}

... will be initialised by a storage object:

const deployContract = async () => {
ttk.wallet.originate({
  code: testJSON,
  storage: {
    res: 0,
    ser: 1
  }
//.send().then(...etc....

2 Answers 2

1

Because the storage is a nat, Taquito expects a number as the storage (not an object):

ttk.wallet.originate({
  code: testJSON,
  storage: 0,
})

I imagine Archetype would give a name to the storage because it is represented as a variable, but if you explore the generated Michelson, you can see that the storage is a single nat value with no annotation:

{ prim: 'storage', args: [{ prim: 'nat' }] }
5
  • Thanks Claude I figured out what was going on via your answer. Turns out that Taquito usually does expect objects as storage for nats, but in the edge case of only a single nat item in the storage, it expects a number.
    – Grum
    Feb 3, 2023 at 22:12
  • This is not exactly true, Taquito expects a number if the storage is a number :) A JavaScript object is only expected as the initial storage when the Michelson type of the storage is a pair. Feb 4, 2023 at 7:37
  • Hey Claude thanks for this feedback - I wasn't quite clear. You can see in the example solution I posted below that in the case where there are two nats in storage, the Originate storage parameter accepts an object with two key-value pairs (which assign each nat to a number).e.g storage: {natOne : 0, natTwo: 1}. However if there is only one nat in storage, Taquito will not accept an object with a single key-value pair (which is what I would have expected). Instead it accepts just a number. That is, it accepts storage: 0 but not storage : { natOne: 0}
    – Grum
    Feb 5, 2023 at 6:24
  • The problem with using a high-level language that compiles to Michelson without knowing Michelson is that it abstracts a lot of things that are actually important. There are never 2 nats in the storage of a contract, the storage is always a single value. I would really recommend you read the Michelson documentation, at least to have some perspective about what Archetype does and how Taquito interacts with the code on-chain. Feb 5, 2023 at 10:08
  • Thanks for the feedback - there is a lot to learn and this has been helpful
    – Grum
    Feb 5, 2023 at 20:49
0

The required syntax here is: storage: 0.

When a contract run through the archetype compiler has only a single nat in storage, the storage parameter to the originate method takes a single value.

When a contract run through the archetype archetype compiler has more than one item in storage, then the storage parameter takes an object. For example this contract...

archetype simple

variable res : nat = 0
variable ser: nat = 1

entry exec (n : nat) {
  res := n
}

... will be initialised by a storage object:

const deployContract = async () => {
ttk.wallet.originate({
  code: testJSON,
  storage: {
    res: 0,
    ser: 1
  }
//.send().then(...etc....
2
  • Once again, this is not exactly true, it has nothing to do with being a rational number or not, a pair can hold a string and a nat or even 2 big_map! It has everything to do with the way Archetype syntax abstracts what's really going on in Michelson. Also, these are not variable names but annotations, they are completely optional in Michelson, but quite useful in general. Feb 5, 2023 at 10:13
  • Okay I've removed my commentary about the michelson which I clearly need to read up on and restricted my answer to the descriptive facts and what I had to do to solve the problem.
    – Grum
    Feb 5, 2023 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.