Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 48 additions & 11 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,6 +176,9 @@ OPTIONS (deploy):
--contract <contractPath> (Optional) Path to the intelligent contract to deploy
--rpc <rpcUrl> RPC URL for the network
--fees <json> Transaction fee options JSON passed to genlayer-js
--fee-profile <path> Fee profile generated by gltest --fee-profile
--fee-preset <preset> Fee profile appeal posture: low, standard, or high
--appeal-rounds <count> Override fee profile appeal rounds
--fee-value <wei> Explicit fee deposit value
--valid-until <timestamp> Unix timestamp after which the transaction is invalid
--args <args...> Contract arguments (see Argument Types below)
Expand All@@ -187,13 +190,19 @@ OPTIONS (call):
OPTIONS (write):
--rpc <rpcUrl> RPC URL for the network
--fees <json> Transaction fee options JSON passed to genlayer-js
--fee-profile <path> Fee profile generated by gltest --fee-profile
--fee-preset <preset> Fee profile appeal posture: low, standard, or high
--appeal-rounds <count> Override fee profile appeal rounds
--fee-value <wei> Explicit fee deposit value
--valid-until <timestamp> Unix timestamp after which the transaction is invalid
--args <args...> Method arguments (see Argument Types below)

OPTIONS (estimate-fees):
--rpc <rpcUrl> RPC URL for the network
--fees <json> Fee estimate options JSON, or a transaction fee object
--fee-profile <path> Fee profile generated by gltest --fee-profile
--fee-preset <preset> Fee profile appeal posture: low, standard, or high
--appeal-rounds <count> Override fee profile appeal rounds
--include-report Include simulation fee accounting/report in the generated estimate output
--args <args...> Method arguments for simulation-derived estimates

Expand All@@ -205,11 +214,14 @@ EXAMPLES:
genlayer deploy --contract ./my_contract.gpy
genlayer deploy --contract ./my_contract.gpy --args "arg1" "arg2" 123
genlayer deploy --contract ./my_contract.gpy --fees '{"distribution":{"leaderTimeunitsAllocation":"100","validatorTimeunitsAllocation":"200","rotations":["0"]}}'
genlayer deploy --contract ./my_contract.gpy --fee-profile ./artifacts/fee-profile.json
genlayer call 0x123456789abcdef greet --args "Hello World!"
genlayer write 0x123456789abcdef updateValue --args 42
genlayer write 0x123456789abcdef updateValue --fees '{"distribution":{"leaderTimeunitsAllocation":"100","validatorTimeunitsAllocation":"200","rotations":["0"]}}' --args 42
genlayer write 0x123456789abcdef updateValue --fee-profile ./artifacts/fee-profile.json --fee-preset standard --args 42
genlayer estimate-fees
genlayer estimate-fees 0x123456789abcdef updateValue --args 42
genlayer estimate-fees 0x123456789abcdef updateValue --fee-profile ./artifacts/fee-profile.json --json
genlayer write 0x123456789abcdef sendReward --args 0x6857Ed54CbafaA74Fc0357145eC0ee1536ca45A0
genlayer write 0x123456789abcdef setScores --args '[1, 2, 3]'
genlayer write 0x123456789abcdef setConfig --args '{"timeout": 30, "retries": 5}'
Expand All@@ -218,6 +230,28 @@ EXAMPLES:

##### Transaction Fee Options

For reproducible application presets, pass the profile produced by
`gltest --fee-profile`:

```bash
genlayer estimate-fees 0x123456789abcdef settle \
--fee-profile ./artifacts/fee-profile.json \
--fee-preset standard \
--json

genlayer write 0x123456789abcdef settle \
--fee-profile ./artifacts/fee-profile.json \
--fee-preset standard
```

`deploy` reads the profile's `deploy` entry. `write` and targeted
`estimate-fees` read `methods[method]`. The CLI converts the measured profile
entry into SDK fee-estimate options, asks `genlayer-js` for a transaction fee
preset, then sends that preset with the transaction. `--fee-preset` controls the
default appeal posture (`low`, `standard`, or `high`); use `--appeal-rounds`
for an explicit override. `--fees` can still be provided alongside
`--fee-profile` to override individual values, including `messageAllocations`.

`--fees` accepts the same transaction fee object as `genlayer-js`. Quote large
integer values as strings to preserve precision. `messageAllocations[].messageType`
may be `"internal"`, `"external"`, `0`, or `1`.
Expand DownExpand Up@@ -253,29 +287,32 @@ preset for reproducible gas-unit debugging.

The `--args` option automatically detects and converts values to the correct type:

| Type | Syntax | Example |
|------|--------|---------|
| Boolean | `true`, `false` | `--args true false` |
| Null | `null` | `--args null` |
| Integer | numeric value | `--args 42 -1` |
| Hex integer | `0x` prefix | `--args 0x1a` |
| String | any other value | `--args hello "multi word"` |
| Address | 40 hex chars with `0x` or `addr#` prefix | `--args 0x6857...a0` or `--args addr#6857...a0` |
| Bytes | `b#` prefix + hex | `--args b#deadbeef` |
| Array | JSON array in quotes | `--args '[1, 2, "three"]'` |
| Dict | JSON object in quotes | `--args '{"key": "value"}'` |
| Type | Syntax | Example |
|----------- | ---------------------------------------- | ----------------------------------------------- |
| Boolean | `true`, `false` | `--args true false` |
| Null | `null` | `--args null` |
| Integer | numeric value | `--args 42 -1` |
| Hex integer | `0x` prefix | `--args 0x1a` |
| String | any other value | `--args hello "multi word"` |
| Address | 40 hex chars with `0x` or `addr#` prefix | `--args 0x6857...a0` or `--args addr#6857...a0` |
| Bytes | `b#` prefix + hex | `--args b#deadbeef` |
| Array | JSON array in quotes | `--args '[1, 2, "three"]'` |
| Dict | JSON object in quotes | `--args '{"key": "value"}'` |

Large numbers that exceed JavaScript's safe integer range are automatically handled as BigInt to preserve precision.

##### Deploy Behavior

- If `--contract` is specified, the command will **deploy the given contract**.
- If `--contract` is omitted, the CLI will **search for scripts inside the `deploy` folder**, sort them, and execute them sequentially.

##### Call vs Write

- `call` - Calls a contract method without sending a transaction or changing the state (read-only)
- `write` - Sends a transaction to a contract method that modifies the state

##### Schema

- `schema` - Retrieves the contract schema

#### Transaction Operations
Expand Down
16 changes: 11 additions & 5 deletions docs/api-references/contracts/deploy.mdx
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,8 +10,14 @@ Deploy intelligent contracts

### Options

| Short | Long | Description | Required | Default |
| --- | --- | --- | :---: | --- |
| | --contract &lt;contractPath&gt; | Path to the smart contract to deploy | No | |
| | --rpc &lt;rpcUrl&gt; | RPC URL for the network | No | |
| -h | --help | display help for command | No | |
| Short | Long | Description | Required | Default |
| ----- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | ------- |
| | --contract &lt;contractPath&gt; | Path to the smart contract to deploy | No | |
| | --rpc &lt;rpcUrl&gt; | RPC URL for the network | No | |
| | --fees &lt;json&gt; | Transaction fee options JSON passed to genlayer-js. | No | |
| | --fee-profile &lt;path&gt; | Path to a fee profile generated by gltest --fee-profile. Deploy uses the profile deploy entry; write and targeted estimate-fees use the matching method entry. --fees can still be provided to override profile values. | No | |
| | --fee-preset &lt;preset&gt; | Fee profile appeal posture: low, standard, or high | No | |
| | --appeal-rounds &lt;count&gt; | Override fee profile appeal rounds | No | |
| | --fee-value &lt;wei&gt; | Fee deposit value to send with the transaction | No | |
| | --valid-until &lt;unixTimestamp&gt; | Unix timestamp after which the transaction is invalid | No | |
| -h | --help | display help for command | No | |
14 changes: 10 additions & 4 deletions docs/api-references/contracts/write.mdx
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,13 @@ Sends a transaction to a contract method that modifies the state

### Options

| Short | Long | Description | Required | Default |
| --- | --- | --- | :---: | --- |
| | --rpc &lt;rpcUrl&gt; | RPC URL for the network | No | |
| -h | --help | display help for command | No | |
| Short | Long | Description | Required | Default |
| ----- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | ------- |
| | --rpc &lt;rpcUrl&gt; | RPC URL for the network | No | |
| | --fees &lt;json&gt; | Transaction fee options JSON passed to genlayer-js. | No | |
| | --fee-profile &lt;path&gt; | Path to a fee profile generated by gltest --fee-profile. Deploy uses the profile deploy entry; write and targeted estimate-fees use the matching method entry. --fees can still be provided to override profile values. | No | |
| | --fee-preset &lt;preset&gt; | Fee profile appeal posture: low, standard, or high | No | |
| | --appeal-rounds &lt;count&gt; | Override fee profile appeal rounds | No | |
| | --fee-value &lt;wei&gt; | Fee deposit value to send with the transaction | No | |
| | --valid-until &lt;unixTimestamp&gt; | Unix timestamp after which the transaction is invalid | No | |
| -h | --help | display help for command | No | |
28 changes: 28 additions & 0 deletions docs/api-references/estimate-fees.mdx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
---
title: estimate-fees
---

Build a transaction fee preset, optionally from a Studio/localnet write
simulation

### Usage

`$ genlayer estimate-fees [options] [contractAddress] [method]`

### Arguments

- `[contractAddress]`
- `[method]`

### Options

| Short | Long | Description | Required | Default |
| ----- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | ------- |
| | --rpc &lt;rpcUrl&gt; | RPC URL for the network | No | |
| | --fees &lt;json&gt; | Fee estimate options JSON passed to genlayer-js estimateTransactionFees. | No | |
| | --fee-profile &lt;path&gt; | Path to a fee profile generated by gltest --fee-profile. Deploy uses the profile deploy entry; write and targeted estimate-fees use the matching method entry. --fees can still be provided to override profile values. | No | |
| | --fee-preset &lt;preset&gt; | Fee profile appeal posture: low, standard, or high | No | |
| | --appeal-rounds &lt;count&gt; | Override fee profile appeal rounds | No | |
| | --json | Print the fee estimate as JSON without spinner output | No | |
| | --include-report | Include simulation fee accounting/report in the generated estimate output | No | |
| -h | --help | display help for command | No | |
1 change: 1 addition & 0 deletions docs/api-references/index.mdx
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,7 @@ Version: `0.34.0`
- `genlayer deploy` — Deploy intelligent contracts
- `genlayer call` — Call a contract method without sending a transaction or changing the state
- `genlayer write` — Sends a transaction to a contract method that modifies the state
- `genlayer estimate-fees` — Build a transaction fee preset, optionally from a Studio/localnet write simulation
- `genlayer schema` — Get the schema for a deployed contract
- `genlayer code` — Get the source for a deployed contract
- `genlayer config` — Manage CLI configuration, including the default network
Expand Down
13 changes: 9 additions & 4 deletions src/commands/contracts/deploy.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ import {BaseAction} from "../../lib/actions/BaseAction";
import {pathToFileURL} from "url";
import {formatStakingAmount} from "genlayer-js";
import {buildSync} from "esbuild";
import {ContractFeeCliOptions, parseTransactionFees, parseValidUntil} from "./fees";
import {ContractFeeCliOptions, parseValidUntil, resolveTransactionFees} from "./fees";
import {assertSuccessfulExecution, transactionConsensusStatus} from "./execution";

export interface DeployOptions extends ContractFeeCliOptions {
Expand DownExpand Up@@ -133,7 +133,10 @@ export class DeployAction extends BaseAction {

const leaderOnly = false;
const deployParams: any = {code: contractCode, args: options.args, leaderOnly};
const fees = parseTransactionFees(options, {deployTargeted: true});
const fees = await resolveTransactionFees(client, options, {
deployTargeted: true,
profileTarget: {kind: "deploy"},
});
const validUntil = parseValidUntil(options);
if (fees) deployParams.fees = fees;
if (validUntil !== undefined) deployParams.validUntil = validUntil;
Expand All@@ -160,8 +163,10 @@ export class DeployAction extends BaseAction {
this.log("Consensus Status:", transactionConsensusStatus(result));

const contractAddress =
result.data?.contract_address ?? // localnet/studio
(result.txDataDecoded as any)?.contractAddress; // testnet
// localnet/studio
result.data?.contract_address ??
// testnet
(result.txDataDecoded as any)?.contractAddress;

this.succeedSpinner("Contract deployed successfully.", {
"Transaction Hash": hash,
Expand Down
Loading
Loading