Jenesis 🦑
📦Install
Install jenesis for Python 3.8 or newer via PyPI:
$ pip3 install jenesis
❓What is Jenesis?
Jenesis is a command line tool for rapid contract and service development for the Fetch.aiblockchain ecosystem and other CosmWasm-enabled blockchains.
🔍Getting Started
There are multiple commands integrated intojenesisthat allow you to perform a variety of tasks, these commands are:
- new
- init
- add
- update
- attach
- compile
- deploy
- run
- shell
- keys
🦑Create a new project
Create a project using thenewcommand
jenesis new my_project
This will create a new directory calledmy_project.Inside this directory a jenesis.toml
file will be created containing the following information:
[project] name = "my_project" authors = [ "Alice Tyler <[email protected]>",] keyring_backend = "os" [profile.testing] default = true [profile.my_profile.network] name = "fetchai-testnet" chain_id = "dorado-1" fee_minimum_gas_price = 5000000000 fee_denomination = "atestfet" staking_denomination = "atestfet" url = "grpc+https://grpc-dorado.fetch.ai" faucet_url = "https://faucet-dorado.fetch.ai" is_local = false [profile.my_profile.contracts]
The project name is the argument passed to thenewcommand while the authors field is populated by querying the user's GitHub username and email address. The profile network is automatically set tofetchai-testnet.
An empty contractsfolder will also be created insidemy_projectdirectory that will contain all the information needed to deploy or compile the desired contracts. Theinitcommand is similar to thenewcommand, but in this case, you won't need a project name argument since this command is intended to run inside an existing project directory.
jenesis init
This command will create the same files and folders inside your project directory as the ones described for thenewcommand.
🧙🏿♂️Add profiles
You can add more profiles than the one specified using thenewcommand by running the followingadd profilecommand:
jenesis add profile my_second_profile
By default, the profile's network will be set to fetchai-testnet
, but you can specify it using the --network
optional argument. The following will be added to the existing information in your jenesis.toml
file:
[profile.my_second_profile.network] name = "fetchai-testnet" chain_id = "dorado-1" fee_minimum_gas_price = 5000000000 fee_denomination = "atestfet" staking_denomination = "atestfet" url = "grpc+https://grpc-dorado.fetch.ai" faucet_url = "https://faucet-dorado.fetch.ai" is_local = false [profile.my_second_profile.contracts]
If there are existing contracts in your project, all of them will be added to the new profile.
📝Add contract templates
Once you have successfully created your project, you can add contract templates. You first need to navigate to your project's directory and run the following command:
jenesis add contract <TEMPLATE> <NAME>
You can find all the contract templates available inJenesis Templates. An example of how to add the template starter
with the name my_first_contract
is given below:
jenesis add contract starter my_first_contract
This add contract command will add a contract template to your jenesis project insidecontracts/my_first_contract/
folder. It will also update the jenesis.toml
configuration file with the contract information under all existing profiles.🧩Compile contracts
Compile your contracts by running the following command inside your project directory:
jenesis compile
This will compile all packages in your project's contracts directory and output the wasm code under the artifacts directory. If using a cargo workspace, jenesis will automatically detect this and the compiled contracts will appear in the contracts/artifacts/
. Otherwise, they will go to the artifacts directory under the individual contracts.
Note that in order to run jenesis compile
you need to have docker running and configured with permissions for your user.
🚀Deploy contracts
Once you have successfully compiled your contracts, make sure to fill out the necessary instantiation message information under the jenesis.toml
file under the init field. You should write it in the following format:
[profile.testing.contracts.my_first_contract.init] count = 5
Then you can run the following command:
jenesis deploy key_name --profile profile_name
You can pass profile_name
as an optional argument to the deploy command who reads the jenesis.toml
file inside the contracts folder, this will indicate which profile's contract or set of contracts will be deployed in the network. If profile isn't specified, it will be set by default to the first profile created. You should also specify the key_name
argument that refers to your local key that will be used to deploy all contracts in the selected profile.
🔗Attach contracts
If you add a contract to the project's contract folder that has already been deployed in the network, you can attach it to your project for future interaction using the attach command.
First, you will need to add the contract and compile it:
jenesis add contract starter my_first_contract jenesis add contract token my_token jenesis compile
Then, you will need to specify the contract'sname
and address
. You can optionally specify the profile where you wish to insert the contract into. If this is not specified, the deployment will be attached to the default profile, which is the first profile created in your project, unless the default settings are manually changed.jenesis attach my_first_contract contract_address --profile my_profile
You will now be able to interact withmy_first_contract
🗝Keys
With thekeyscommand you can either list all the keys locally available or show the address of a specific key. To list all the keys available run the following command:
jenesis keys list
To look up the address for a specified key you can use theshowcommand and pass the key name as an argument:
jenesis keys show my_key
To access other key functionalities such as adding new keys, looking up an address, and recovering keys you can usefetchd CLI - Managing Keys
🏄🏽♂️Interact with Contracts
To reproduce the examples in this section, add and compile a basic starter contract and a cw20 token contract to your project with the following commands:
jenesis add contract starter my_first_contract jenesis add contract token my_token jenesis compile
For more contract template examples visitJenesis Templates.
You can interact with your project's contracts by using theshell command:
jenesis shell
You will observe the following text indicating the available contracts in your project.
Detecting contracts... Network: fetchai-testnet C my_first_contract C my_token Detecting contracts...complete
In this case, we can see that my_first_contract and my_token contracts are available for this project. If these contracts have been already deployed you can directly interact with them by performing contract executions such as:
>>> my_first_contract.execute(args = {'msg_name': {...}})
A ledger client (ledger) and your locally stored wallet keys will also be available in the shell. For example, if you have a local key named alice, you will find this under wallets['alice']
and you can query the balance as follows:
>>> ledger.query_bank_balance(wallets['alice']) 10000000000000000000
If the ledger is a testnet with a faucet url, you can get funds using the faucet:
>>> faucet.get_wealth(wallets['alice'])
You can also assemble multiple commands into a script that is executable by the runcommand.
from cosmpy.aerial.wallet import LocalWallet wallet = LocalWallet.generate() faucet.get_wealth(wallet.address()) wallet2 = LocalWallet.generate() my_token.deploy(name="Crab Coin", symbol="CRAB", decimals=6, initial_balances=[{ "address": str(wallet.address()), "amount" : "5000"}], sender=wallet) print("wallet initial cw20 MT balance: ", my_token.balance(address=str(wallet.address()))) tx = my_token.transfer(amount='1000', recipient=str(wallet2.address()), sender=wallet) print("transfering 1000 cw20 MT tokens from wallet to wallet2") tx.wait_to_complete() print("wallet final cw20 MT balance: ", my_token.balance(address=str(wallet.address()))) print("wallet2 final cw20 MT balance: ", my_token.balance(address=str(wallet2.address())))
If we paste the above code into the file script.py inside the project's directory, we can run it with:
jenesis run script.py
And you will see the output on the terminal
🥇What's next?
Mastered all of the above? Great! But you have only scratched the surface. Check out ourmain documentation sitefor more guides and resources.