CLI error "Error parsing arguments: SyntaxError: Unexpected token h in JSON at position 1"

I am trying to send a transaction using oz send-tx and put as argument an url string (type of function argument is a string) and geting a error:
Error parsing arguments: SyntaxError: Unexpected token h in JSON at position 1

Here is an example of raw url (I have tried to escape special characters but result the same )
https://gist.githubusercontent.com/username/3bde88a0e8248c73c68c1aed2ca4b9be/raw/41e604b8603d4cf83a42c7de21f8438848ac6a36/ORG.ID

How to properly escape url string to avoid an error?
note: this error is appearing in non-interactive mode

Can you try enclosing the URL in single quotes and double quotes? Something like:

$ oz send-tx --to ADDRESS --method METHOD --args '"https://gist.githubusercontent.com/username/3bde88a0e8248c73c68c1aed2ca4b9be/raw/41e604b8603d4cf83a42c7de21f8438848ac6a36/ORG.ID"'
1 Like

Thanks @spalladino

That worked on my example

Box.sol

pragma solidity ^0.5.0;

contract Box {
    string private value;

    // Emitted when the stored value changes
    event ValueChanged(string newValue);

    // Stores a new value in the contract
    function store(string memory newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    // Reads the last stored value
    function retrieve() public view returns (string memory) {
        return value;
    }
}

Set value using the CLI (non-interactive)

npx oz send-tx --method store --args '"https://example.com"' --network development --to 0xe982E462b094850F12AF94d21D470e21bE9D0E9C

Thank you very much. “single quotes and double quotes” is working fine, sorry for the late response

2 Likes

No problem! Apologies for the complexity of the solution by the way. The outermost quotes are used so Bash does not try to parse the contents, and the innermost are so the CLI knows that everything in there belongs to a single string.

1 Like