genlayer 0.36.1 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +24 -3
  2. package/dist/index.js +67 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -174,15 +174,15 @@ USAGE:
174
174
  OPTIONS (deploy):
175
175
  --contract <contractPath> (Optional) Path to the intelligent contract to deploy
176
176
  --rpc <rpcUrl> RPC URL for the network
177
- --args <args...> Positional arguments for the contract (space-separated, use quotes for multi-word arguments)
177
+ --args <args...> Contract arguments (see Argument Types below)
178
178
 
179
179
  OPTIONS (call):
180
180
  --rpc <rpcUrl> RPC URL for the network
181
- --args <args...> Positional arguments for the method (space-separated, use quotes for multi-word arguments)
181
+ --args <args...> Method arguments (see Argument Types below)
182
182
 
183
183
  OPTIONS (write):
184
184
  --rpc <rpcUrl> RPC URL for the network
185
- --args <args...> Positional arguments for the method (space-separated, use quotes for multi-word arguments)
185
+ --args <args...> Method arguments (see Argument Types below)
186
186
 
187
187
  OPTIONS (schema):
188
188
  --rpc <rpcUrl> RPC URL for the network
@@ -193,9 +193,30 @@ EXAMPLES:
193
193
  genlayer deploy --contract ./my_contract.gpy --args "arg1" "arg2" 123
194
194
  genlayer call 0x123456789abcdef greet --args "Hello World!"
195
195
  genlayer write 0x123456789abcdef updateValue --args 42
196
+ genlayer write 0x123456789abcdef sendReward --args 0x6857Ed54CbafaA74Fc0357145eC0ee1536ca45A0
197
+ genlayer write 0x123456789abcdef setScores --args '[1, 2, 3]'
198
+ genlayer write 0x123456789abcdef setConfig --args '{"timeout": 30, "retries": 5}'
196
199
  genlayer schema 0x123456789abcdef
197
200
  ```
198
201
 
202
+ ##### Argument Types
203
+
204
+ The `--args` option automatically detects and converts values to the correct type:
205
+
206
+ | Type | Syntax | Example |
207
+ |------|--------|---------|
208
+ | Boolean | `true`, `false` | `--args true false` |
209
+ | Null | `null` | `--args null` |
210
+ | Integer | numeric value | `--args 42 -1` |
211
+ | Hex integer | `0x` prefix | `--args 0x1a` |
212
+ | String | any other value | `--args hello "multi word"` |
213
+ | Address | 40 hex chars with `0x` or `addr#` prefix | `--args 0x6857...a0` or `--args addr#6857...a0` |
214
+ | Bytes | `b#` prefix + hex | `--args b#deadbeef` |
215
+ | Array | JSON array in quotes | `--args '[1, 2, "three"]'` |
216
+ | Dict | JSON object in quotes | `--args '{"key": "value"}'` |
217
+
218
+ Large numbers that exceed JavaScript's safe integer range are automatically handled as BigInt to preserve precision.
219
+
199
220
  ##### Deploy Behavior
200
221
  - If `--contract` is specified, the command will **deploy the given contract**.
201
222
  - If `--contract` is omitted, the CLI will **search for scripts inside the `deploy` folder**, sort them, and execute them sequentially.
package/dist/index.js CHANGED
@@ -20078,7 +20078,7 @@ var require_cli_table3 = __commonJS({
20078
20078
  import { program } from "commander";
20079
20079
 
20080
20080
  // package.json
20081
- var version = "0.36.1";
20081
+ var version = "0.37.0";
20082
20082
  var package_default = {
20083
20083
  name: "genlayer",
20084
20084
  version,
@@ -55120,19 +55120,72 @@ var CodeAction = class extends BaseAction {
55120
55120
  };
55121
55121
 
55122
55122
  // src/commands/contracts/index.ts
55123
- function parseArg(value, previous = []) {
55124
- if (value === "true") return [...previous, true];
55125
- if (value === "false") return [...previous, false];
55126
- if (!isNaN(Number(value))) return [...previous, Number(value)];
55127
- return [...previous, value];
55123
+ var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
55124
+ var ADDR_PREFIX_RE = /^addr#([0-9a-fA-F]{40})$/;
55125
+ var BYTES_PREFIX_RE = /^b#([0-9a-fA-F]*)$/;
55126
+ var HEX_RE = /^0x[0-9a-fA-F]+$/;
55127
+ function hexToBytes4(hex) {
55128
+ const bytes = new Uint8Array(hex.length / 2);
55129
+ for (let i2 = 0; i2 < bytes.length; i2++) {
55130
+ bytes[i2] = parseInt(hex.slice(i2 * 2, i2 * 2 + 2), 16);
55131
+ }
55132
+ return bytes;
55128
55133
  }
55134
+ function coerceValue(value) {
55135
+ if (value === null) return null;
55136
+ if (typeof value === "boolean") return value;
55137
+ if (typeof value === "number") {
55138
+ if (Number.isSafeInteger(value)) return value;
55139
+ return BigInt(value);
55140
+ }
55141
+ if (Array.isArray(value)) return value.map(coerceValue);
55142
+ if (typeof value === "object" && value !== null) {
55143
+ const result = {};
55144
+ for (const [k, v] of Object.entries(value)) {
55145
+ result[k] = coerceValue(v);
55146
+ }
55147
+ return result;
55148
+ }
55149
+ if (typeof value === "string") return parseScalar(value);
55150
+ return value;
55151
+ }
55152
+ function parseScalar(value) {
55153
+ if (value === "null") return null;
55154
+ if (value === "true") return true;
55155
+ if (value === "false") return false;
55156
+ const addrMatch = value.match(ADDR_PREFIX_RE);
55157
+ if (addrMatch) return new CalldataAddress(hexToBytes4(addrMatch[1]));
55158
+ if (ADDRESS_RE.test(value)) return new CalldataAddress(hexToBytes4(value.slice(2)));
55159
+ const bytesMatch = value.match(BYTES_PREFIX_RE);
55160
+ if (bytesMatch) return hexToBytes4(bytesMatch[1]);
55161
+ if (HEX_RE.test(value)) return BigInt(value);
55162
+ if (!isNaN(Number(value)) && Number.isSafeInteger(Number(value))) return Number(value);
55163
+ if (!isNaN(Number(value))) return BigInt(value);
55164
+ return value;
55165
+ }
55166
+ function parseArg(value, previous = []) {
55167
+ try {
55168
+ const parsed = JSON.parse(value);
55169
+ if (typeof parsed === "object" || Array.isArray(parsed)) {
55170
+ return [...previous, coerceValue(parsed)];
55171
+ }
55172
+ } catch {
55173
+ }
55174
+ return [...previous, parseScalar(value)];
55175
+ }
55176
+ var ARGS_HELP = [
55177
+ "Contract arguments. Supported types:",
55178
+ " bool: true, false",
55179
+ " null: null",
55180
+ " int: 42, -1, 0x1a (large values auto-use BigInt)",
55181
+ ' str: hello, "multi word"',
55182
+ " address: 0x6857...a0 (40 hex chars) or addr#6857...a0",
55183
+ " bytes: b#deadbeef",
55184
+ ` array: '[1, 2, "three"]'`,
55185
+ ` dict: '{"key": "value"}'`
55186
+ ].join("\n");
55129
55187
  function initializeContractsCommands(program2) {
55130
- program2.command("deploy").description("Deploy intelligent contracts").option("--contract <contractPath>", "Path to the smart contract to deploy").option("--rpc <rpcUrl>", "RPC URL for the network").option(
55131
- "--args <args...>",
55132
- "Positional arguments for the contract (space-separated, use quotes for multi-word arguments)",
55133
- parseArg,
55134
- []
55135
- ).action(async (options) => {
55188
+ program2.command("deploy").description("Deploy intelligent contracts").option("--contract <contractPath>", "Path to the smart contract to deploy").option("--rpc <rpcUrl>", "RPC URL for the network").option("--args <args...>", ARGS_HELP, parseArg, []).action(async (options) => {
55136
55189
  const deployer = new DeployAction();
55137
55190
  if (options.contract) {
55138
55191
  await deployer.deploy(options);
@@ -55143,7 +55196,7 @@ function initializeContractsCommands(program2) {
55143
55196
  });
55144
55197
  program2.command("call <contractAddress> <method>").description("Call a contract method without sending a transaction or changing the state").option("--rpc <rpcUrl>", "RPC URL for the network").option(
55145
55198
  "--args <args...>",
55146
- "Positional arguments for the method (space-separated, use quotes for multi-word arguments)",
55199
+ ARGS_HELP,
55147
55200
  parseArg,
55148
55201
  []
55149
55202
  ).action(async (contractAddress, method, options) => {
@@ -55152,7 +55205,7 @@ function initializeContractsCommands(program2) {
55152
55205
  });
55153
55206
  program2.command("write <contractAddress> <method>").description("Sends a transaction to a contract method that modifies the state").option("--rpc <rpcUrl>", "RPC URL for the network").option(
55154
55207
  "--args <args...>",
55155
- "Positional arguments for the method (space-separated, use quotes for multi-word arguments)",
55208
+ ARGS_HELP,
55156
55209
  parseArg,
55157
55210
  []
55158
55211
  ).action(async (contractAddress, method, options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genlayer",
3
- "version": "0.36.1",
3
+ "version": "0.37.0",
4
4
  "description": "GenLayer Command Line Tool",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",