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