Polylang
CLI
This assumes that you have cloned the repository locally, and built it as described in the Building Polylang section.
Suppose we have a contract representing an account:
contract Account {
id: string;
name: string;
setName(newName: string) {
this.name = newName;
}
}
Suppose we have a sample record like so:
{
"id": "id1",
"name": "John"
}
We wish to change the value of the name
field from "John" to "Tom" by invoking the setName
function defined in the contract.
We can compile and run this contract using the Polylang
CLI as explained next:
$ cargo run --bin compile -- contract:Account function:setName <<< 'contract Account { id: string; name: string; function setName(newName: string) { this.name = newName; } }' \
| cargo run -p miden-run -- \
--this-json '{ "id": "id1", "name": "John" }' \
--advice-tape-json '["Tom"]'
A brief explanation of the command:
- We compile the contract passing in the contract name (using the
contract:
marker) and the function of interest (using thefunction:
marker) as well as the body of the contract itself. - The compilation step produces bytecode for the Miden VM as well as a
Polylang
specific ABI JSON text representing the processed contract. - We then pipe the output from the compilation step to the
miden-run
executable by passing in:- the record input using the
--this-json
flag. In this case, it's a contract record containing two fields:id
andname
. - the new value for the
name
field using the--advice-json
flag.
- the record input using the
This produces:
<extraneous output redacted>
this_json: {"id":"id1","name":"Tom"}
As we can see, the record has been updated, reflecting the name change:
{
"id": "id1",
"name": "Tom"
}