# Smart Contract Commands

# Compile Contract

# Usage

Usage: miyabi-cli compilecontract [Options]

Options:
--help                  Show help information
-f|--file <path>        Paths to the source file to be compiled
-d|--dependency <name>  Assembly name the source has dependency
--offline               Use basic compilation rules for local debugging (without customized rules of the running miyabi).

# Functionality

An offline command that compiles the given smart contract to make sure it can be deployed smoothly. -f and -d are required that can be used multiple times to specify all source files and libraries. If the specific library is not on the white list, the command will fail. Success will return the assembly id

# Example

$ ./miyabi-cli.exe compilecontract -f sc1.cs -d miyabi.Binary.Models -d miyabi.ModelSdk
ed67603f2aac8cc2c5ef5feb9b42af9a56de4178e2a3be4c3bc765491b4c2079

# Get Assembly Id

# Usage

Usage: miyabi-cli getassemblyid [Options]

Options:
--help            Show help information
-f|--file <path>  Paths to the source file

# Functionality

An offline command that calculates the assembly id of the smart contract without compiling the source code. -f is required and can be used multiple times to support multiple files for one smart contract.

# Example

$ ./miyabi-cli.exe getassemblyid -f sc1.cs
ed67603f2aac8cc2c5ef5feb9b42af9a56de4178e2a3be4c3bc765491b4c2079

# Get Contract Address

# Usage

Usage: miyabi-cli getcontractaddress [Options]

Options:
--help                              Show help information
-a|--assembly-id <assembly-id>      Assembly Id
-c|--contract-name <contract-name>  Contract Name
-i|--instance-name <name>           Instance name

# Functionality

Online general reference command that will return the address of the smart contract instance. The address is used as the public key of the smart contract that only the smart contract can use. Contract name is the full name of the class include the namespace. All options except --help are required.

# Example

$ ./miyabi-cli.exe getcontractaddress -a 67fb1fba5539e041bac59e00241d8edfdca254ab9a5174987bd205fa7b5bfa4f -c miyabi.Tests.SC1 -i test_sc1_instance
80ccc328b84770e42d2263d6a76fea52eb0bff40340a083bda68c65c0dde84dda7

# Get Assemblies

# Usage

Usage: miyabi-cli getassemblies [Options]

Options:
--help  Show help information

# Functionality

Online general reference command that lists all deployed smart contract's assembly Id.

# Example

$ ./miyabi-cli.exe getassemblies
["09e87e0921869507bec81e0578d26f5b3338ba42cad0cf3713eadb1e9a356ac3","0f71271c032c653b1aee757641c005003d20956f742213a63a862dc9bbcff80f",...]

# Get Instances

# Usage

Usage: miyabi-cli getinstances [Options]

Options:
--help  Show help information

# Functionality

Online general reference command that lists all instantiated smart contract's instance records.

# Example

$ ./miyabi-cli.exe getinstances
{
  "22b7d8a2ab6bd4e8a6d50d5b4ea8a2a97db1a83222b32bcab24bb7a97c785cf2": {
    "assemblyId": "ed67603f2aac8cc2c5ef5feb9b42af9a56de4178e2a3be4c3bc765491b4c2079",
    "contractName": "miyabi.Tests.SC1",
    "instanceName": "instance_20200225175642135h7dQSEBHgX"
  },
  "3e9415feec5aaa690fec53e5edf732448a101facbe06a5f5cd2721fa53ed2aeb": {
    "assemblyId": "9657f2da7fb0e420b529d58d32115ca4b77d59b401a4bdfaab861276ccec2261",
    "contractName": "SmilesContract.SmilesContract",
    "instanceName": "demo"
  },
  ....

# Query Contract

# Usage

Usage: miyabi-cli querycontract [Options]

Options:
--help                  Show help information
-m|--method <string>    Method name
-i|--instance <string>  Instance name
-c|--contract <string>  Contract name
-a|--assemblyid <hex>   Assembly ID
-p|--parameter <hex>    Parameters to the method

# Functionality

Online general reference command that queries an instantiated smart contract's query method. The return type of the method specified by --method should be the type of query result (not void). The contract name should be the full name contains the namespace. Every option except --help and -p (if no parameters are required by this method) are required.

# Example

$ ./miyabi-cli.exe querycontract -a 67fb1fba5539e041bac59e00241d8edfdca254ab9a5174987bd205fa7b5bfa4f -c miyabi.Tests.SC1 -i test_sc1_instance -m Read -p 1111
"2222"

# Deploy Contract

# Usage

Usage: miyabi-cli sendtransaction deploycontract [Options] [-- InnerCommand [InnerCommand Options] <arg(s)>]

Options:
--help                                         Show help information
-p|--privatekey <key>            Private keys of contract admins
-f|--file <path>                        Paths to the contract source
-i|--instantiator <address>  Addresses who can instantiate
-d|--dependency <name>      Assembly name of dependencies
--debug                                      Deploy as debuggable contract

# Functionality

Transaction subcommand that will deploy a smart contract.-p should be the private key of contract admin. -d should specify all libraries required by the smart contract, if the library is not in the white list of miyabi, the transaction could be failed. -i specify the public key of instantiator that only these instantiator can instantiate the assembly. -f supports to be used multiple times. -p, -f, -i are required.

# Example

$ ./miyabi-cli.exe sendtransaction deploycontract -p 14e3a2d16c8a43a4eb1b088b32bca2abaf274e3f185afc9c15b33491c8deb9a6 -i 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 -f sc1.cs -d miyabi.Binary.Models -d miyabi.ModelSdk
0083b12ba492fa2c38cd8c21cce90eeb56c2e4b442f9baeb4f45f6016dd1620f

# Instantiate Contract

# Usage

Usage: miyabi-cli sendtransaction instantiatecontract [Options] [-- InnerCommand [InnerCommand Options] <arg(s)>]

Options:
--help                          Show help information
-p|--privatekey <key>           Private keys (should include at least one table admin and contract instantiator)
-a|--assembly <id>              Assembly ID
-c|--contract <name>            Contract name
-i|--instance <name>            Instance name
-o <address>|--owner <address>  Address of Instance Owner. Deletion of instance requires it's signature
--argument <value>              Arguments for the contract constructor

# Functionality

Transaction subcommand that will instantiate a deployed smart contract owned by address o. -p should include both table admin and instantiator of the assembly. -c should be the full name of the class that inherited from contractbase. All options but --help and --argument(depends on the definition in the smart contract) are required.

# Example

$ ./miyabi-cli.exe sendtransaction instantiatecontract -p 01 -p 10425b7e6ebf5e0d5918717f77ce8a66aaf92bc64b65996f885ff12bd94ef529 -a 67fb1fba5539e041bac59e00241d8edfdca254ab9a5174987bd205fa7b5bfa4f -c miyabi.Tests.SC1 -i test_sc1_instance --argument dummy
7712535ac74a2567fd456726acd82d96fae49aa82c888260fe4a9ec5a7a44e07

# Invoke Contract

# Usage

Usage: miyabi-cli sendtransaction invokecontract [Options] [-- InnerCommand [InnerCommand Options] <arg(s)>]

Options:
--help                 Show help information
-p|--privatekey <key>  Private key of user (or valid signer as defined in contract)
-a|--assembly <id>     Assembly ID
-c|--contract <name>   Contract name
-i|--instance <name>   Instance name
-m|--method <name>     Method name
--argument <value>     Arguments for the contract

# Functionality

Transaction subcommand that will invoke the method of an instantiated smart contact. The return type of the method specified by --method should be void. -p is required for signing the transaction, which can be arbitrary private key depends on the signature required by the smart contract. --argument is optional if the method does not require input. The class parameters should be inputted as the form of JSON string. -p, -a, -c, -i, and -m are required.

# Example

$ ./miyabi-cli.exe sendtransaction invokecontract -a 67fb1fba5539e041bac59e00241d8edfdca254ab9a5174987bd205fa7b5bfa4f -c miyabi.Tests.SC1 -i test_sc1_instance -p 01 -m Write --argument 1111 --argument 2222
f76f01358d9f04f9982dced015d68f0762e3f87e60d9bf6c033e56f0aa596181

# Delete Contract Instance

# Usage

Usage: miyabi-cli sendtransaction deletecontractinstance [Options] [-- InnerCommand [InnerCommand Options] <arg(s)>]

Options:
--help                 Show help information
-p|--privatekey <key>  Private keys (should include table admins and contract instantiators)
-a|--assembly <id>     Assembly ID
-c|--contract <name>   Contract name
-i|--instance <name>   Instance name

# Functionality

Transaction subcommand will delete one existed instance of a smart contract. All options but --help are required.

# Example

$ ./miyabi-cli.exe sendtransaction deletecontractinstance -p 01 -p 10425b7e6ebf5e0d5918717f77ce8a66aaf92bc64b65996f885ff12bd94ef529 -a 67fb1fba5539e041bac59e00241d8edfdca254ab9a5174987bd205fa7b5bfa4f -c miyabi.Tests.SC1 -i test_sc1_instance
b1895869ce09373d1d7435d24f307768183b3743c1ac5c2972f63dd9be033cca

# Initialize Contract

# Usage

Usage: miyabi-cli sendtransaction initializecontract [Options] [-- InnerCommand [InnerCommand Options] <arg(s)>]

Options:
--help                 Show help information
-p|--privatekey <key>  Private keys (should include table and contract admins)
--admin <address>      Contract admins
--enable-debugging     Enable contract debugging

# Functionality

Transaction subcommand that can initialize the contract module of the Miyabi and specify the contract admins who can deploy smart contracts. All contract admins in --admin should sign the transaction as well as a table admin. If --enable-debugging is true, the smart contract can be deployed under debug mode. -p and --admin is required.

# Example

$ ./miyabi-cli.exe sendtransaction initializecontract -p 01 -p 10425b7e6ebf5e0d5918717f77ce8a66aaf92bc64b65996f885ff12bd94ef529 --admin 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
680989cea8cd405835c6bdd3b78194b7c73de826167d7da7caff055f7f2d278e

# Note

This transaction will only success once.

# Get Contract Analyzer Parameters

# Usage

Usage: miyabi-cli getcontractanalyzerparameters

Options:
--help                 Show help information

# Functionality

List all parameters such as AllowedAssemblies ForbiddenMembers for the smart contract analyzer

# Example

$ ./miyabi-cli.exe getcontractanalyzerparameters
{"AllowedAssemblies":["Miyabi.NodeSdk","Miyabi.Asset.Models","Miyabi.Binary.Models","Miyabi.Common","Miyabi.Contract.Models","Miyabi.Contract.Dependencies","Miyabi.ContractSdk","Miyabi.Cryptography.Secp256k1","Miyabi.Entity.Models","Miyabi.ModelSdk","Miyabi.NFT.Models","System","System.Collections","System.Collections.Immutable","System.Core","System.Linq","System.Net.Security","System.Private.CoreLib","System.Runtime","mscorlib","netstandard","Newtonsoft.Json"],"AllowedMembers":["Miyabi.Asset.Models","Miyabi.Binary.Models","Miyabi.ByteString","Miyabi.Common","Miyabi.Contract.Models","Miyabi.Contract.Dependencies","Miyabi.ContractSdk","Miyabi.Cryptography","Miyabi.Entity.Models","Miyabi.ModelSdk","Miyabi.NodeSdk","Miyabi.ReadOnlyEnumerableHelper","Miyabi.NFT.Models",,"System.Array","System.DateTime","System.DateTimeOffset","System.Guid","System.Boolean","System.Byte","System.SByte","System.Char","System.Decimal","System.Double","System.Single","System.Int32","System.UInt32","System.Int64","System.UInt64","System.Int16","System.UInt16","System.String","System.Text","System.Object","System.BitConverter","System.Collections","System.Linq.Enumerable","Newtonsoft.Json"],"ForbiddenMembers":["System.Guid.NewGuid","System.DateTime.Now","System.DateTime.Today","System.DateTime.UtcNow","System.DateTimeOffset.Now","System.DateTimeOffset.UtcNow"]}

# Update Contract Analyzer

# Usage

Usage: miyabi-cli sendtransaction updatecontractanalyzer  [Options]

Options:
--help                            Show help information
-p <key>|--privatekey <key>       Keys for signing this transaction, world admin is required"
-o <string>|--operation <string>  Specify the parameters to be modified" - (AllowedAssemblies,AllowedMembers,ForbiddenMembers)
-a <string>|--add <string>        List of memebrs to add, specify the full name of item (e.g. System.Object)
-r <string>|--remove <string>     List of memebrs to remove, specify the full name of item (e.g. System.Object)

# Functionality

Subcommand used to update the parameter analyzer by adding or removing assemblies and or memebrs. p and o are required.

# Example

$ ./miyabi-cli.exe sendtransaction updatecontractanalyzer -p a9e45d133cd24a623143962a87ad0e89a0c5c9764a0ec9f936fa5aa4278b30a3 -o AllowedMembers -a System.Linq
680989cea8cd405835c6bdd3b78194b7c73de826167d7da7caff055f7f2d278e

# Update Contract Permission

# Usage

Usage: miyabi-cli sendtransaction updatecontractpermission  [Options]

Options:
--help                            Show help information
-p <key>|--privatekey <key>       Private Key(s) of the permission assigners
--grant <string>                  Specify the permissions to be added - (Deploy, GrantDeploy)
--revoke <string>                 Specify the permissions to be removed - (Deploy, GrantDeploy)
--address <address>               Specify the addresses to be updated


# Functionality

Subcommand used to grant or revoke permissions for addresses --addresses

# Example

$ ./miyabi-cli.exe sendtransaction updatecontractpermission -p a9e45d133cd24a623143962a87ad0e89a0c5c9764a0ec9f936fa5aa4278b30a3 -o AllowedMembers -a System.Linq
680989cea8cd405835c6bdd3b78194b7c73de826167d7da7caff055f7f2d278e