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....