Skip to content

Instantly share code, notes, and snippets.

@shubhamkumar13
Created June 1, 2023 08:04
Show Gist options
  • Save shubhamkumar13/aa71c2c62d62ad2f90efd1ce7d08647d to your computer and use it in GitHub Desktop.
Save shubhamkumar13/aa71c2c62d62ad2f90efd1ce7d08647d to your computer and use it in GitHub Desktop.
From a beginners perspective
  1. Startup should be before Install taq plugins

    • makes it less confusing for beginners who might get an error This doesn't appear to be a taqueria project. and get stuck.
    • also in the command add a mkdir <insert-dir-name> for a root directory so that they know not to install it in their $HOME or any global scope just as an extra piece of caution
  2. Initialize/create's root directory should be specified helps in understanding where the contract would be created using taq create ... command.

    • maybe let users know it's a template for a counter, helpful context but it's optional.
    • do update the code since it is different from the template generated
        cat intezos.jsligo
      
        type storage = int;
      
        type parameter =
          ["Increment", int]
        | ["Decrement", int]
        | ["Reset"];
      
        type ret = [list<operation>, storage];
      
        // Two entrypoints
      
        const add = ([store, delta] : [storage, int]) : storage => store + delta;
        const sub = ([store, delta] : [storage, int]) : storage => store - delta;
      
        /* Main access point that dispatches to the entrypoints according to
           the smart contract parameter. */
      
        const main = ([action, store] : [parameter, storage]) : ret => {
         return [list([]) as list<operation>,    // No operations
         match (action, {
          Increment:(n: int) => add ([store, n]),
          Decrement:(n: int) => sub ([store, n]),
          Reset    :()  => 0})]
        };
  3. Defining storage should ideally be called updating the storage with a differnt type which is needed for the payment contract.

  4. Defining entrypoint again can be updating entrypoint because there is already a function like that in the template, maybe deleting and updating the template functions can be section on it's own.

  5. Code verification/compilation mentions creation of 2 new files - intezos.parameterList.jsligo and intezos.storageList.jsligo, specifying the location can be helpful, for me it was created in <root-dir>/contracts/contracts

    • I got some error with ligo run dry-run contracts/intezos.jsligo 'unit' '{ amount: 100000 as mutez, receiver: "tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq" as address, secret: { question: "Do you like Paul", encrypted_answer: Crypto.sha256(Bytes.pack("yes he is awesome but encrypted")) }, sender: "tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq" as address, pending: true }' --entry-point claim
      ❯ ligo run dry-run contracts/intezos.jsligo 'unit' '{ amount: 100000 as mutez, receiver: "tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq" as address, secret: { question: "Do you like Paul", encrypted_answer: Crypto.sha256(Bytes.pack("yes he is awesome but encrypted")) }, sender: "tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq" as address, pending: true }' --entry-point claim
        Error(s) occurred while parsing the Michelson input:
        At (unshown) location 0, value
          (Pair Unit
                (Pair (Pair 100000 True)
                      "tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq"
                      0xd4d6835d2c877b78a46521738a9876206af5f5e1a71beda8d0bdf37f55506309
                      "Do you like Paul")
                "tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq")
        is invalid for type
          pair unit (pair (pair mutez bool) address string string) address.
        At (unshown) location 0, value
          (Pair (Pair (Pair 100000 True)
                      "tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq"
                      0xd4d6835d2c877b78a46521738a9876206af5f5e1a71beda8d0bdf37f55506309
                      "Do you like Paul")
                "tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq")
        is invalid for type
          pair (pair (pair mutez bool) address string string) address.
        At (unshown) location 2, value
          (Pair (Pair 100000 True)
                "tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq"
                0xd4d6835d2c877b78a46521738a9876206af5f5e1a71beda8d0bdf37f55506309
                "Do you like Paul")
        is invalid for type pair (pair mutez bool) address string string.
        At (unshown) location 2, value
          (Pair "tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq"
                0xd4d6835d2c877b78a46521738a9876206af5f5e1a71beda8d0bdf37f55506309
                "Do you like Paul") is invalid for type pair address string string.
        At (unshown) location 2, value
          (Pair 0xd4d6835d2c877b78a46521738a9876206af5f5e1a71beda8d0bdf37f55506309
                "Do you like Paul") is invalid for type pair string string.
        At (unshown) location 7, value
          0xd4d6835d2c877b78a46521738a9876206af5f5e1a71beda8d0bdf37f55506309
        is invalid for type string.
        At (unshown) location 7, unexpected byte sequence, only a string
        can be used here.
      maybe I am doing something wrong here because when I define intezos.runner.jsligo which contains essentially the same info it works without any issue
        ❯ ligo run dry-run contracts/intezos.runner.jsligo 'unit' 'default_storage' --entry-point claim
        ( LIST_EMPTY() ,
          record[amount -> 100000mutez ,
                 pending -> False(unit) ,
                 receiver -> @"tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq" ,
                 secret -> record[encrypted_answer -> "yes he is awesome but encrypted" ,
                                  question -> "Do you like Paul"] ,
                 sender -> @"tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq"] )
  6. Implementing conditions has a specific command where the sender is specified

      ligo run dry-run contracts/intezos.runner.jsligo 'claim_default_parameter' 'default_storage' --entry-point claim --sender 'tz1Yj4FviaKEy6ER8ZDeiH2w2Lx8bapjuJEq'

    since the sender name is essentially the same as the initial name spotting where mutation happens is hard. Maybe changing it something readable would be easier to spot.

I wasn't able to understand Implements the transfer maybe separating the concepts from the code might be helpful

I also didn't try to deploy it on the testnet, I'll try that and update the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment