1

I'm following the https://baking-bad.github.io/pytezos/#originate-contract refs to originate a contract. I suspect that it has something to do with how I usually iniatialize the storage, so if anyone can help me with that I would be really greatful, I'm digging it forever.

While trying to deploy I get the following error:

Michelson error:

Traceback (most recent call last):

  File "<ipython-input-47-c91371e05a4c>", line 1, in <module>
    runfile('~/testpytezos.py', wdir='~')

  File "~/.local/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "~/.local/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "~/testpytezos.py", line 33, in <module>
    op = pytezos.origination(script=contract.script()).autofill().sign().inject()

  File "/usr/local/lib/python3.6/dist-packages/pytezos/operation/group.py", line 171, in autofill
    raise RpcError.from_errors(OperationResult.errors(opg_with_metadata)) from None

MichelsonRuntimeError: ({'id': 'proto.005-PsBabyM1.michelson_v1.unexpected_annotation',
  'kind': 'permanent',
  'location': 8},)

Micheline error:


  File "/home/crzy/Documents/hicetnunc/tezos-storage-flask/testpytezos.py", line 30, in <module>
    contract = Contract.from_file('./smart_contracts/transaction_micheline.tz')

  File "/usr/local/lib/python3.6/dist-packages/pytezos/michelson/contract.py", line 306, in from_file
    return cls.from_michelson(f.read())

  File "/usr/local/lib/python3.6/dist-packages/pytezos/michelson/contract.py", line 296, in from_michelson
    return cls(michelson_to_micheline(text))

  File "/usr/local/lib/python3.6/dist-packages/pytezos/michelson/micheline.py", line 493, in michelson_to_micheline
    return michelson_parser().parse(data)

  File "/usr/local/lib/python3.6/dist-packages/pytezos/michelson/grammar.py", line 163, in parse
    return self.parser.parse(code)

  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)

  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 1201, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)

  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 192, in call_errorfunc
    r = errorfunc(token)

  File "/usr/local/lib/python3.6/dist-packages/pytezos/michelson/grammar.py", line 152, in p_error
    raise MichelsonParserError(p)

MichelsonParserError: LexToken([,'[',1,0)

context:

python code:

with open('./faucets/tz1WGhT231BgqK7CrjbMB5xDsbdDSBJZiw5E.json') as json_file:
    data = json.load(json_file)

pytezos = pytezos.using(
        key='./faucets/tz1WGhT231BgqK7CrjbMB5xDsbdDSBJZiw5E.json',
        shell='babylonnet')

r = requests.post('http://hicetnunc.glitch.me/api/reveal', json=data)
print (r.json().get('privateKey'))

pytezos.using(key=r.json().get('privateKey'))

contract = Contract.from_file('./smart_contracts/transaction.tz')
print(contract.script)

op = pytezos.origination(script=contract.script()).autofill().sign().inject()

Michelson smartcontract code:

parameter (or (or (nat %divisor) (unit %double)) (nat %value));

storage (nat %storedValue);

code
  {
    DUP;
    CDR;
    SWAP;
    CAR;
    IF_LEFT
      {
        IF_LEFT
          {
            PAIR;
            DUP;
            CAR;
            PUSH nat 5;
            SWAP;
            COMPARE;
            GT;
            IF
              {
              }
              {
                PUSH string "WrongCondition: params.divisor > 5";
                FAILWITH;
              };
            DUP;
            CDR;
            DUUP;
            CAR;
            EDIV;
            IF_SOME
              {
                CAR;
              }
              {
                PUSH string "division by zero";
                FAILWITH;
              };
            SWAP;
            DROP;
            NIL operation;
            PAIR;
          }
          {
            PAIR;
            DUP;
            CDR;
            PUSH nat 2;
            MUL;
            SWAP;
            DROP;
            NIL operation;
            PAIR;
          };
      }
      {
        PAIR;
        DUP;
        CAR;
        SWAP;
        DROP;
        NIL operation;
        PAIR;
      };
  }

  • 1
    1) the smartpy contract you point to has nothing to do with the michelson you put in your question so please ask one question per distinct issue 2) your smartpy contract hardcodes nonsensical tezos address as constants in the storage so it is not expected to be deployable. – Ezy Feb 19 at 2:54
  • It would be useful to have the initial SmartPy script and the version used. – FFF Feb 19 at 2:59
  • 1
    @Ezy indeed, the michelson I posted was not related to the smartpy code I provided, I'm sorry about that. The code on smartpy ui did compile without any edits actually. Thanks for the caution and attention you all. – crzy Feb 19 at 3:18
  • @FFF It's the pretifier example, actually. – crzy Feb 19 at 3:18
  • The prettifier example has been cooked up by hand by removing some random parts of an actual generated contract. It's not a real example and I didn't know anyone tried to originate it. – FFF Feb 19 at 3:44
3

The problem is with the storage annotation (%storedValue), if you remove it, everything works.
In the storage section, field annotations (starting with %) are allowed in components of pair types, option types and or types.

| improve this answer | |
1

As Michael points out, in this case the problem was due to a malformed contract, and thus has nothing to do with tezospy. A tips is to first verify that your contract typechecks, using try-michelson for instance.

| improve this answer | |

Your Answer

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

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