gen client. Steps 1–5 use simple-token from Build your first contract; Composing with another contract deploys a second token instance and an exchange that references both.
Contract setup on the Grid is staged:
- Push publishes compiled code. Upload the artifact bundle from your
*_modules.jsonmanifest; the chain stores the code and returns acontract_code_id. The same push can back many deploys. - Deploy instantiates that code, creating a root component on an entity. The runtime runs the contract’s
#[deploy]hook once and returns acontractaddress androot_component_id. - Install adds non-root components from the contract on an entity. Deploy already creates the root component; install is for every other component type the contract defines.
Prerequisites
- The
genCLI configured against DevNet. See Configuring for DevNet. - A built contract manifest at
<contract>/artifacts/<contract>_modules.json. See Build your first contract. - A funded DevNet wallet — your entity on chain and the key that signs activations. The manifest is what you push; the wallet publishes code, receives the deployed instance, and signs every state-changing step. Follow Quickstart Steps 3–4.
--account:
Step 1: Push the contract code
Fromdemos/from-token-to-amm:
contract_code_id; you need it for deploy.
Step 2: Deploy an instance
#[deploy] takes parameters, pass them as JSON via --deploy-params. Simple-token for example requires name and symbol:
GvmContract argument (composing with another deployed contract), see Composing with another contract below.
The result includes two fields you need:
contract: the bech32m address of the deployed instance. Pass this toinstall.root_component_id: a 4-part, comma-separated string for the root component. Method calls on other components use the 4-partcomponent_idreturned byinstall.
Step 3: Install components
Simple-token defines issuer (component_type_index 1) and holder (2). Install each on the deployed instance:
Step 4: Call a state-changing method
Two CLI commands: build the unsigned activation, then sign and submit it. Mint on the issuer;dest is the holder’s 4-part component_id, and amount is a single-element tuple:
outcome_result is the method’s return value, Borsh-encoded as hex.
Step 5: Call a view method
decoded field shows the return value as a string.
Composing with another contract
Some contracts’#[deploy] takes a GvmContract argument pointing at a contract you’ve already deployed. The CLI rejects bech32m strings or hex bytes for this parameter; it accepts only one specific nested-tuple JSON shape.
In from-token-to-amm, the exchange contract composes with two simple-token instances — one GvmContract parameter per token (token_a_contract, token_b_contract). Token A is already deployed from Steps 1–5 above.
The JSON shape
GvmContract parameter on #[deploy]. Wrap the 32-byte entity id in four JSON arrays (one per newtype layer: EntityId → H256 → [u8; 32] → the bytes). Use plain u8 integers, not a hex string. Wrap the u32 component index in one array.
Deriving the values from a bech32m address
Decode thecontract address from gen client deploy to get the entity bytes and component_index. Until gen client decode ships, use this Python snippet:
Deploy Token B and the exchange
Build the exchange manifest, deploy a second token from the samecontract_code_id, then push and deploy the exchange. Decode both token contract addresses with the Python snippet above before the final deploy:
Troubleshooting
error: unexpected argument '--rpc-url'. Somegen clientsubcommands take--rpc-urlafterclient, others take it after the subcommand. If unsure, set the URL once on your active environment (gen config env set --rpc <url>, orgen config env new/switch) and drop the flag.Invalid GvmComponentId format: expected 2 or 4 bech32m parts.--component-idneeds the full 4-part comma-separatedroot_component_idfromdeploy, not the singlecontractaddress.Type mismatch for 'X': expected object, got string.--deploy-paramsis rejecting a typed SDK argument. See Composing with another contract for the JSON shape.
What’s next
- Genie SDK reference: the full surface area of the SDK these contracts are built on.
- from-token-to-amm: the simple-token and exchange contracts used in this guide.
