0

I have a simple smart contract on the Tezos blockchain that contains a pair of a set of addresses and a counter in its storage. The contract has a single entrypoint that allows setting the storage to a given value:

{ parameter (pair (set %addresses address) (nat %counter)) ;
  storage (pair (set %addresses address) (nat %counter)) ;
  code { CAR ; NIL operation ; PAIR } }

I want to interact with this contract using @taquito. Here is my script:

import { TezosToolkit } from '@taquito/taquito';
import { InMemorySigner } from '@taquito/signer';
import dotenv from 'dotenv';


async function main() {
  dotenv.config();
  const Tezos = new TezosToolkit(process.env.RPC_NODE);
  const signer = await InMemorySigner.fromSecretKey(process.env.PRIVATE_KEY);
  Tezos.setProvider({ signer: signer });

  const account = await Tezos.signer.publicKeyHash();
  const contract = await Tezos.contract.at(process.env.CONTRACT_ADDRESS);
  const params = {
    'addresses': [account],
    'counter': 420
  };

  const operation = await contract.methods.default(params).send();
  await operation.confirmation();
}

main();

When I run the script, I get the following error: SetValidationError(value, this, 'Value must be an array'). Here is the full error stack:

/home/reproduce-taquito-set/node_modules/@taquito/michelson-encoder/dist/taquito-michelson-encoder.umd.js:2357
          return new SetValidationError(value, this, 'Value must be an array');
                 ^

SetValidationError: [addresses] Value must be an array
    at SetToken.isValid (/home/reproduce-taquito-set/node_modules/@taquito/michelson-encoder/dist/taquito-michelson-encoder.umd.js:2357:18)
    at SetToken.Encode (/home/reproduce-taquito-set/node_modules/@taquito/michelson-encoder/dist/taquito-michelson-encoder.umd.js:2361:28)
    at /home/reproduce-taquito-set/node_modules/@taquito/michelson-encoder/dist/taquito-michelson-encoder.umd.js:718:48
    at Array.map (<anonymous>)
    at PairToken.Encode (/home/reproduce-taquito-set/node_modules/@taquito/michelson-encoder/dist/taquito-michelson-encoder.umd.js:718:35)
    at ParameterSchema.Encode (/home/reproduce-taquito-set/node_modules/@taquito/michelson-encoder/dist/taquito-michelson-encoder.umd.js:3805:32)
    at ContractMethod.toTransferParams (/home/reproduce-taquito-set/node_modules/@taquito/taquito/dist/taquito.umd.js:3090:48)
    at ContractMethod.send (/home/reproduce-taquito-set/node_modules/@taquito/taquito/dist/taquito.umd.js:3068:52)
    at main (file:///home/reproduce-taquito-set/interact.js:19:60)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  value: {
    addresses: [ 'tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb' ],
    counter: 420
  },
  token: SetToken {
    val: {
      prim: 'set',
      args: [ { prim: 'address' } ],
      annots: [ '%addresses' ]
    },
    idx: 0,
    fac: [Function: createToken],
    createToken: [Function: createToken]
  }
}

It seems that I am not correctly constructing the set of addresses. How should I pass a set of addresses as a parameter when calling a contract using Taquito?

UPDATE: to simplify reproducing process I deployed this contract to ghostnet: KT1UYWUkUvcsYdiRoefuc9CageoqGRVvcXzP

UPDATE 2: here is github repo with this contract and script: https://github.com/ztepler/reproduce-taquito-set

1 Answer 1

1

The error is, I believe, from how you are passing the params to the contract.methods.default params should be passed as contract.methods.default([address], 420)

I hope this helps. Let me know if you need any other help!

other options is:

const operation = await contract.methodsObject.default({addresses: [account], counter: 420})

using methodsObject which will accept the object format

1
  • 1
    Wow, it really was that easy! Your suggestion with methodsObject works for both this dummy contract and the one I'm working with. Looks like I mixed up methods and methodsObject. Thanks you! However this is strange that nothing is said about this methodsObject in the documentation, on those pages that I read: [1] tezostaquito.io/docs/complex_parameters [2] tezostaquito.io/docs/quick_start
    – ztepler
    Apr 27 at 20:56

Your Answer

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

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