Skip to main content

Chinstrap REPL

chinstrap:>

Chinstrap provides a develop sub-command that provides a repl to develop interactively. chinstrap develop launches a powerful repl, exposing Chinstrap's functionalitiy to the repl making the interaction with Tezos networks much easier.

โžœ chinstrap develop -h

repl

To start a local sandbox on port 12345, and generate 5 test accounts and use Ithaca protocol, and launch the repl, run the following command:

chinstrap develop -p Ithaca -n development -o 12345 -c 5

asciicast

Available functions:

pytezos
config
network
getContract
getContractFromFile
getContractFromURL
getContractFromAddress
compile
test
template
JsLigo
CameLIGO
ReasonLIGO
PascaLIGO
accounts
sandbox
stopSandbox
originate
install
compilers
exit

configโ€‹

config is a Chinstrap config object that gives you access to current project's configuration file.

chinstrap:> print(config)

Config

getContractโ€‹

getContract method takes name of a contract from contracts folder to fetch and return pytezos.ContractInterface.

chinstrap:> help(getContract)
getContract(name)
Get contract to be originated.
arguments:
name: name of the contract from contracts/ folder to get
returns :
pytezos.ContractInterface
chinstrap:> contract = getContract("MyContract")
chinstrap:> contract
pytezos.jupyter.ContractInterface object at 0x104dd6e80>

Properties
.block_id head
.storage # access storage data at block `block_id`
.parameter # root entrypoint

Entrypoints
.approve()
.getAllowance()
.getBalance()
.getTotalSupply()
.transfer()
.default()

Views

Helpers
.big_map_get()
.create_from()
.from_context()
.from_file()
.from_micheline()
.from_michelson()
.from_url()
.metadata()
.metadata_url()
.operation_result()
.originate()
.program()
.script()
.storage_from_file()
.storage_from_micheline()
.storage_from_michelson()
.to_file()
.to_micheline()
.to_michelson()
.using()
chinstrap:> contract.storage
<pytezos.contract.data.ContractData object at 0x104057610>

Properties
.block_id head
.path

Builtin
() # get as Python object
[key] # access child elements by name or index

Typedef
$storage:
{
"allowances": { ( address, address ): nat, โ€ฆ } || int /* Big_map ID */,
"tokens": { address: nat, โ€ฆ } || int /* Big_map ID */,
"total_supply": nat
}

$address:
str /* Base58 encoded `tz` or `KT` address */

$nat:
int /* Natural number */


Helpers
.decode()
.default()
.dummy()
.encode()
.to_micheline()
.to_michelson()
chinstrap:>

getContractFromFileโ€‹

getContractFromFile method takes a contract from michelson source code stored in a file and returns pytezos.ContractInterface.

chinstrap:> help(getContractFromFile)
getContractFromFile(filename)
Get contract from michelson source code stored in a file and returns.
arguments:
filename: filename of the contract to get
returns :
pytezos.ContractInterface
chinstrap:> contract = getContractFromFile("./build/contracts/MyContract/step_000_cont_0_contract.tz")
chinstrap:> contract.storage
<pytezos.contract.data.ContractData object at 0x10a36fe20>

Properties
.block_id head
.path

Builtin
() # get as Python object
[key] # access child elements by name or index

Typedef
$storage:
{
"allowances": { ( address, address ): nat, โ€ฆ } || int /* Big_map ID */,
"tokens": { address: nat, โ€ฆ } || int /* Big_map ID */,
"total_supply": nat
}

$address:
str /* Base58 encoded `tz` or `KT` address */

$nat:
int /* Natural number */


Helpers
.decode()
.default()
.dummy()
.encode()
.to_micheline()
.to_michelson()

getContractFromURLโ€‹

getContractFromURL method is same as getContractFromFile method takes a contract from michelson source code available via URL and returns pytezos.ContractInterface.

getContractFromAddressโ€‹

getContractFromAddress method fetches pytezos.ContractInterface interface from a given contract address.

contract contract storage

compileโ€‹

Chinstrap repl also has a compile function that compiles contracts inside contracts folder.

chinstrap:> help(compile)
compile(contract=None, local=False, werror=False, warning=False, entrypoint='main')

compile

testโ€‹

Chinstrap repl also has a test function that run tests inside tests folder.

chinstrap:> help(test)
test(test=None, local=False, entrypoint='main')

test

originateโ€‹

Chinstrap repl provides originate method to originate contracts.

chinstrap:> help(originate)
originate(originate=None, number=None, network='development', port=20000, reset=False, show=False, force=False, contract=None, local=False, werror=False, warning=False, entrypoint='main')

chinstrap:> originate()

originate

chinstrap:> originate(originate="originations/1_samplecontract_origination.py", contract="contracts/MyContract.mligo")

originate

templateโ€‹

Chinstrap repl has template function that replicates the behaviour of chinstrap template command.

chinstrap:> help(template)
template(language=<enum 'TemplateOptions'>)

template

accountsโ€‹

Using accounts method, you can access list of accounts generated by sandbox.

chinstrap:> accounts()

accounts

sandboxโ€‹

Now you can control sandbox from the repl using sandbox() method

chinstrap:> help(sandbox)
sandbox(initialize=False, port=20000, detach=True, num_of_accounts=10, minimum_balance=20000, protocol=<SandboxProtocols.hangzhou: 'Hangzhou'>, list_accounts=False, stop=False)

sandbox

To generate more accounts in sandbox, we can use _sandbox.generateAccounts method

_sandbox.generateAccounts(num_of_accounts=10)

Sandbox Accounts

stopSandboxโ€‹

You can halt the running local sandbox using this method.

chinstrap:> stopSandbox()
โœ” Halted the sandbox
chinstrap:>

installโ€‹

To install compilers, we can use install method.

chinstrap:> install(compiler=<enum 'Compilers'>, local=False, force=False)

install

pytezosโ€‹

PyTezos library is a Python toolset for Tezos blockchain, including work with keys, signatures, contracts, operations, RPC query builder, and a high-level interface for smart contract interaction. Documentation for pytezos can be accessed here.

exitโ€‹

To exit the repl, you can run exit method.

chinstrap:> exit()

exit