I have defined a type Poll using a struct. I would like to be able to instantiate it, preferably passing initial values to its variables when I do. eg I would imagine a syntax for what I want to do something like:

let Poll poll = new Poll ({cost : mutez 100});

or let Poll poll = (cost : mutez 100);

The best I can do right now is to instantiate an empty default of each type in storage and then initialise them with a contract call, which seems a little ugly, as well as being an unnecessary cost.

storage Poll defPoll;

entry initateTypes(Poll defPoll){
  storage.defPoll = input.defPoll

entry newPoll(string url, mutez cost){
  let Poll poll = storage.defPoll;
  poll.owner = SENDER;
  poll.payer = SENDER;
  poll.cost = input.cost;

  storage.polls.push(input.url, poll);
  • Just as a warning: i am not sure FI is actively maintained any more (the latest commit is 11 months ago on the fi github). I would use either SmartPy or LIGO as actively developped and maintained high level languages for tezos for mainnet deployment – arvidj Mar 12 at 14:24
  • Could you show the full code of your contract? Where is Poll defined? You mention structs, but I see no mention of structs in the fi manual. – arvidj Mar 12 at 14:29
  • Thanks for that info - I was not aware of this and thought that FI was new! (BTW the Poll could be any struct, in this case, having a single member, cost. structs are on the front page of learn.fi-code.com and compile fine) – mork Mar 15 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.