Search code examples
invalid-argument

brun: error: unrecognized Arguments - Chialisp


I am following a very basic chialisp tutorial to create a very basic (insecure) smart contract on the chia blockchain.

The chialisp code behind is:

(mod (
        password_hash
        password
        receive_puzzlehash
        transaction_amount
    )
    (if (= (sha256 password) password_hash)
        ; true - password was correct
        (list
            (list CREATE_COIN receive_puzzlehash transaction_amount)
        )
        ; false - password was incorrect
        (x "Bad password")
    )
)

At this stage it is still mostly learning the syntax. I compile the code into low level code as such:

(venv) Y:\Chialisp\Legacycoin Tutorialcoin>cdv clsp build passwordprotect.clsp
Beginning compilation of passwordprotect.clsp...
...Compilation finished

(venv) Y:\Chialisp\Legacycoin Tutorialcoin>run passwordprotect.clsp
(a (i (= (sha256 5) 2) (q 4 (c (q . "CREATE_COIN") (c 11 (c 23 ()))) ()) (q 8 (q . "Bad password"))) 1)

Then I try to execute the puzzlehash / program:

(venv) Y:\Chialisp\Legacycoin Tutorialcoin>brun "(a (i (= (sha256 5) 2) (q 4 (c (q . "CREATE_COIN") (c 11 (c 23 ()))) ()) (q 8 (q . "Bad password"))) 1)" "(0x9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 test 0xa11ce 1000)"
usage: brun [-h] [--strict] [-x] [-s STAGE] [-v] [-t] [-c] [--time] [-m MAX_COST] [-d] [--quiet] [-y SYMBOL_TABLE] [-n] [--backend BACKEND] [-i INCLUDE] path_or_code [env]
brun: error: unrecognized arguments: (0x9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 test 0xa11ce 1000)

(venv) Y:\Chialisp\Legacycoin Tutorialcoin>

What does the unrecognized arguments error mean? Is there an issue with my input format? Is there an error to compile one of the arguments? I cannot see any diference from the Tutorial except I am using double quotes (on windows cmd) and the tutorial (on linux) uses single quotes. Using single quotes did not help.


Solution

  • Error:

    1. Do not use CMD for executing chialisp code. Although it works to some degree, plenty of stuff does not. enter image description here

    2. Double quoting inside of each other cancles out. In the above screenshot, this is not visible but powershell with syntax highlighting makes this quite obvious: enter image description here

    Solution:

    1. Use PowerShell instead on windows. enter image description here

    2. Use single quotes for encapsulation such as:

    '(a (q 2 (i (= (sha256 11) 5) (q 4 (c 2 (c 23 (c 47 ()))) ()) (q 8 (q . "Bad password"))) 1) (c (q . 51) 1))'
    

    IMPORTANT: windows powershell has inverse quoting standards from linux. This means on Windows, the outer quotes need to be inversed:

    "(a (i (= (sha256 5) 2) (q 4 (c (q . 'CREATE_COIN') (c 11 (c 23 ()))) ()) (q 8 (q . 'Bad password'))) 1)"