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 Templates. An example of how to add the template starter with the name
my_first_contractis given below:
add contract command will add a contract template to your jenesis project inside
contracts/my_first_contract/ folder. It will also update the
jenesis.toml configuration file with the contract information under all existing profiles.
deployer_keyfield can be manually specified, you can choose any private key locally available to deploy any specific contract. You can also leave this field empty since the
deploycommand has an optional argument to deploy all contracts inside a specified profile with the same key, overriding this
deployer_keyargument in the
jenesis.tomlfile. See deploy contracts for more information.
init section contains the parameters needed in the instantiation message for this contract to be deployed. The required parameters are taken from the
instantiate_msg.json file inside the
contracts directory. You will need to manually add the values for these parameters in their correct variable type, which are listed in
contracts/my_first_contract/schema/instantiate_msg.json. For this contract my_first_contract we need to add an integer value to the
If your contract requires nested instantiation messages you may add fields following this structure:
NOTE: Before editing the
jenesis.tomlconfiguration file with the desired
initparameters, make sure to first compile your contract. All configuration parameters will restart every time a contract is compiled to make sure everything is up to date.
You can also add contracts manually by copying and pasting the contract directory from another project you may have, however, they need to follow the same directory structure as the starter template mentioned above.
When you add a contract manually, you need to update the
jenesis.toml file with the contract information by running:
updatecommand will automatically detect which contract is missing in the
jenesis.tomlconfiguration file by revising the contracts directory.
Add contract deployments¶
You can add multiple deployments for any given contract in your project by running:
[profile.testing.contracts.my_first_contract] name = "my_first_contract" contract = "my_first_contract" network = "fetchai-testnet" deployer_key = "alice" init_funds = "" [profile.testing.contracts.my_first_contract.init] count = 1 [profile.testing.contracts.deployment_name] name = "deployment_name" contract = "my_first_contract" network = "fetchai-testnet" deployer_key = "alice" init_funds = "" [profile.testing.contracts.deployment_name.init] count = 1
Attach deployed contracts¶
If you add a contract into 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
To add a contract to yout project you can run:
If you add the contract just by copying and pasting it, you will need to run:
Then compile the contract:
To attach the contract, you will need to specify the contract's name and deployment 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.
This will add the relevant deployment information into a
jenesis.lock file and you will now be able to interact with
my_first_contract using contract interactions