3

I was trying to deploy a vote smart contract on Tezos using tezos-client but because of initilization issue nothing was happening the right way.

The smart contract code in liquidity ( you can see the Mickelson code by compiling it with https://www.liquidity-lang.org/edit/ ):

[%%version 0.9]

type storage = {
candidates: (string, int) map ;
voters: (address, bool) map }

[%%init
let init_candidates (candidate_names : string list) =
let candidates =
  List.fold (fun (elt,map)  -> Map.add elt 0 map) candidate_names
    (((Map ([]))[@explicit_arity ]) : (string, int) map)
in
{
  candidates = candidates;
  voters = (Map : (address, bool) map)
} ]

[%%entry
let main (parameter : string) (storage : storage) =

let stroage =
  storage.candidates <-
    (match Map.find parameter storage.candidates with
     | None  -> failwith ("Candidate is not valid", parameter)
     | ((Some (x))[@explicit_arity ]) ->
         Map.add parameter (x + 1) storage.candidates)
in

(([] : operation list), storage) ]

Command used to deploy:

./tezos-client originate contract vote transferring 0 from alice 
running ../vote.tz --init '["Alice" ; "Bob" ; "Jack"]' --burn-cap 
0.429

Error:

At line 1 character 0, unexpected character [
At line 1 character 27, unexpected character ]
At line 1 characters 9 to 10, unexpected semi colon
At line 1 characters 11 to 17, unexpected string constant
At line 1 characters 18 to 19, unexpected semi colon
At line 1 characters 20 to 27, unexpected string constant

I found an other way to initiate the storager using "Paie" and "Elt", so I tried to deploy:

./tezos-client originate contract votesec transferring 0 from Khalil 
running ../vote.tz --init '(Pair {Elt "Alice" 0 ; Elt "Bob" 0})'

And I got this error:

Ill typed data: 1: (Pair { Elt "Alice" 0 ; Elt "Daly" 0 })
is not an expression of type
pair :storage (map %candidates string int) (map %voters address bool)
At line 1 characters 0 to 38,
primitive Pair expects 2 arguments but is given 1.

Can anyone help me out and explain to me what's wrong?

Thank you in advance.

2
  • Fyi: Liquidity is no longer an officially supported high level language in tezos. You may want to migrate your development to better offers including smartpy, ligo and lorentz
    – Ezy
    Commented Dec 23, 2019 at 13:23
  • Thank you, it's solved by initiating this way: --init '(Pair { Elt "Alice" 0 ; Elt "Daly" 0 } {})'
    – Daly
    Commented Dec 23, 2019 at 14:42

1 Answer 1

3

After compiling in the liquidity IDE, we see that the type of the storage is

storage (pair :storage (map %candidates string int) (map %voters address bool));

For the initialization, the annotations (:storage,%candidates and %voters) can be ignored. As you can see, the type of the storage is a pair of values: the map of candidates and the map of voters. Whereas in your command line, you use the Pair constructor, but you give only value. Try this instead, where an empty map ({}) as the second component of the pair:

--init '(Pair { Elt "Alice" 0 ; Elt "Daly" 0 } {})'

You can also use the try-michelson editor to obtain valid initial values for the storage:

1
  • Thnak you! That solved my problem! This is the right command to launch: ./tezos-client originate contract vote transferring 0 from Khalil running ../vote.tz --init '(Pair { Elt "Alice" 0 ; Elt "Daly" 0 } {})' --burn-cap 0.815
    – Daly
    Commented Dec 23, 2019 at 14:41

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.