Sending transactions and queries
Using Gamma CLI
Transactions are different from read-only queries by the fact they're able to change state. Transactions require consensus by several nodes whereas read-only queries can rely on a single node.
Send transactions to contracts by running gamma-cli send-tx
and giving a JSON file containing the call arguments.
For example, to send the transaction with arguments in transfer.json
Perform queries and call read-only contract methods by running gamma-cli run-query
and giving a similar JSON file.
For example, to make the read call with arguments in get-balance.json
Command parameters
<INPUT_FILE>
Path of the JSON file containing the call arguments-signer
Account ID of the signer of the call (fromorbs-test-keys.json
)-arg#
Override the value of argument number # from the input call argument JSON
Call argument JSON
This simple JSON file is used to let Gamma CLI know which contract method should be executed and what arguments should be passed to it.
An example of such a JSON is
The ContractName should be the name chosen during deployment of the contract with gamma-cli deploy
. The method name should be one of the exported methods found in the contract source code.
The array of arguments should be given according to the declaration of the method in contract source code.
Supported argument types
uint32
- Integer with 32 bit precision. Matches theuint32
type in Go contracts. Provided in the JSON as a string of a decimal number. For example
uint64
- Integer with 64 bit precision. Matches theuint64
type in Go contracts. Provided in the JSON as a string of a decimal number. For example
string
- String. Matches thestring
type in Go contracts. Provided in the JSON as a UTF8 string. For example
bytes
- An array of bytes (blob). Matches the[]byte
type in Go contracts. Provided in the JSON as a hex string. For example
bool
- boolean value. Matches thebool
type in Go contracts. Provided in the JSON as a string with value"0"
or"1"
. For example
uint256
- Integer with 256 bit precision. Matches the*big.Int
type in Go contracts. Provided in the JSON as a hex string with fixed size of 64 hexes. For example
bytes20
- A fixed size array of 20 bytes. Matches the[20]byte
type in Go contracts. Provided in the JSON as a hex string with fixed size of 40 hexes. For example
bytes32
- A fixed size array of 32 bytes. Matches the[32]byte
type in Go contracts. Provided in the JSON as a hex string with fixed size of 64 hexes. For example
All the slice of these types are also supported. The type has the suffix 'Array' and the value is JSON Array of strings representing the values. For example
In addition to these primitives, Gamma CLI supports several aliases for convenience:
gamma:keys-file-address
- An account address by ID. The value should be an account ID fromorbs-test-keys.json
. An alias for the typebytes
which means it matches the[]byte
type in Go contracts. Used to pass the account address in raw form.
Overriding arguments from command line
Consider a JSON for a typical transfer method
The first argument is the amount and the second argument is the recipient address.
If you want to send multiple transactions with different amounts or different addresses, creating multiple JSON files containing the different values can be a hassle.
Instead, use the optional -arg1
and -arg2
command line arguments to override values
will send 15 tokens to recipient b3d1caa2b3680e2c8feffa269c207c553fbbc828
will send 22 tokens to recipient b3d1caa2b3680e2c8feffa269c207c553fbbc828
will send 15 tokens to recipient 7ccd7f7c18c0cb749dd8b8949f4b4e31f7188394
When the type is an Array (slice) should be a STRINGIFIED JSON representation for example if the type is a boolArray the override value can be something like this :
"[\"0\", \"1\", \"1\"] - this is a string representation of []bool{false, true, true}
Last updated