CLI

The NEM2 Command Line Interface is a unified tool to interact with the NEM blockchain.

This tool will enable you to perform the most common used actions to interact with the blockchain.

NEM2-CLI is an open source tool built on top of the NEM2-SDK Typescript. Use it in your favorite terminal program.

Installation

NEM2-CLI is distributed using the node package manager npm.

To install:

sudo npm install --global nem2-cli

To update:

sudo npm update --global nem2-cli

Configuration

To start using NEM2-CLI, configure a profile.

A profile holds an account and a node url for a specific network. Profiles are used to set a base url and have an account to sign transactions.

Configure default profile.

nem2-cli profile create --private-key your_private_key --network MIJIN_TEST --url http://localhost:3000

NEM2-CLI supports named profiles. You can configure additional profiles by using the –profile option.

nem2-cli profile create --private-key your_private_key --network MIJIN_TEST --url http://localhost:3000 --profile mijin_test_net_profile

By default, NEM2-CLI will always use the default profile. To use a named profile, add the –profile option to the command.

nem2-cli account info --profile mijin_test_net_profile

If you do not have a private key to create a profile you can generate a new account, add a node url and save it as default or named profile.

nem2-cli account generate --network MIJIN_TEST -s --url http://localhost:3000 --profile mijin_test_net_profile

Commands

Profile

Create

Creates a new profile.

Options

-p, --private-key <privateKey> - Account private key.
-n, --network <network>        - Network Type. Example: MAIN_NET, TEST_NET, MIJIN, MIJIN_TEST.
-u, --url <url>                - NEM2 Node URL. Example: http://localhost:3000
--profile <profile>            - (Optional) Profile name, if not private key will override the default profile.

Command

nem2-cli profile create --private-key your_private_key --network MIJIN_TEST --url http://localhost:3000 --profile test

List

Displays the list of stored profiles.

Command

nem2-cli profile list

Note

By default, NEM2-CLI will always use the default profile to connect to a node and set default options such as: address, public key and sign transactions with private key. To use a named profile, add the –profile option to any command.

Account

Generate new account

Generates a new account. This command generates a private key, public key and address.

Generated accounts can be stored as named profiles by adding a node url.

Options

-s, --save              - (Optional) Saves the profile
-u, --url <url>         - (Optional) When saving profile, provide a NEM2 Node URL. Example: http://localhost:3000
--profile <profile>     - (Optional) When saving profile you can add profile name, if not will be stored as default.
-n, --network <network> - Network Type (MAIN_NET, TEST_NET, MIJIN, MIJIN_TEST).

Command

nem2-cli account generate --network MIJIN_TEST

Get account info

Returns the account information, such as the public key, importance and mosaics balance.

Options

--profile <profile>     - (Optional) Select between your profiles, by providing a profile name.
-a, --address <address> - Account address.

Command

nem2-cli account info --address SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54

Get confirmed transactions

Gets an array of transactions for which an account is the sender or receiver.

Options

Fetch transactions from account

  --profile <profile>                      - (Optional) Select between your profiles, by providing a profile name.
  -p, --public-key <publicKey>             - Account public key.
  -n, --num-transactions <numTransactions> - (Optional) Number of transactions. [10]
  -i, --id <id>                            - (Optional) Identifier of the transaction after which we want the transactions to be returned.

Command

nem2-cli account transactions --public-key 7D08373CFFE4154E129E04F0827E5F3D6907587E348757B0F87D2F839BF88246 --numtransactions 10

Get incoming transactions

Gets an array of incoming transactions. A transaction is said to be incoming with respect to an account if the account is the recipient of the transaction.

Options

--profile <profile>                      - (Optional) Select between your profiles, by providing a profile name.
-p, --public-key <publicKey>             - Account public key.
-n, --num-transactions <numTransactions> - (Optional) Number of transactions. [10]
-i, --id <id>                            - (Optional) Identifier of the transaction after which we want the transactions to be returned.

Command

nem2-cli account incoming --public-key 7D08373CFFE4154E129E04F0827E5F3D6907587E348757B0F87D2F839BF88246

Get outgoing transactions

Gets an array of outgoing transactions. A transaction is said to be outgoing with respect to an account if the account is the sender of the transaction.

Options

--profile <profile>                      - (Optional) Select between your profiles, by providing a profile name.
-p, --public-key <publicKey>             - Account public key.
-n, --num-transactions <numTransactions> - (Optional) Number of transactions. [10]
-i, --id <id>                            - (Optional) Identifier of the transaction after which we want the transactions to be returned.

Command

nem2-cli account incoming --public-key 7D08373CFFE4154E129E04F0827E5F3D6907587E348757B0F87D2F839BF88246

Get unconfirmed transactions

Gets the array of transactions for which an account is the sender or receiver and which have not yet been included in a block.

Options

--profile <profile>                      - (Optional) Select between your profiles, by providing a profile name.
-p, --public-key <publicKey>             - Account public key.
-n, --num-transactions <numTransactions> - (Optional) Number of transactions. [10]
-i, --id <id>                            - (Optional) Identifier of the transaction after which we want the transactions to be returned.

Command

nem2-cli account unconfirmed --public-key 7D08373CFFE4154E129E04F0827E5F3D6907587E348757B0F87D2F839BF88246

Get aggregate bonded transactions

Gets an array of aggregate bonded transactions where the account is the sender or requires to cosign the transaction.

Options

--profile <profile>                      - (Optional) Select between your profiles, by providing a profile name.
-p, --public-key <publicKey>             - Account public key.
-n, --num-transactions <numTransactions> - (Optional) Number of transactions. [10]
-i, --id <id>                            - (Optional) Identifier of the transaction after which we want the transactions to be returned.

Command

nem2-cli account aggregatebonded --public-key 7D08373CFFE4154E129E04F0827E5F3D6907587E348757B0F87D2F839BF88246

Block

Header

Returns the block header by height.

Options

--profile <profile>        - (Optional) Select between your profiles, by providing a profile name.
-h, --height <height>      - Block height.

Command

nem2-cli block header --height 1

Transactions

Returns the transactions for a given block height.

Options

--profile <profile>        - (Optional) Select between your profiles, by providing a profile name.
-h, --height <height>      - Block height.
-s, --page-size <pageSize> - (Optional) Page size between 10 and 100. Default: 10
-i, --id <id>              - (Optional) Id after which we want objects to be returned.
-o, --order <order>        - (Optional): Order of transactions. DESC. Newer to older. ASC. Older to newer. Default: DESC

Command

nem2-cli block transactions --height 1

Receipts

Returns the receipts for a given block height.

Options

--profile <profile>        - (Optional) Select between your profiles, by providing a profile name.
-h, --height <height>      - Block height.

Command

nem2-cli block receipts --height 1

Chain

Chain height

Returns the current height of the block chain.

Options

--profile <profile>                      - (Optional) Select between your profiles, by providing a profile name.

Command

nem2-cli chain height

Chain score

Gets the current score of the block chain. The higher the score, the better the chain. During synchronization, nodes try to get the best block chain in the network.

Options

--profile <profile>  - (Optional) Select between your profiles, by providing a profile name.

Command

nem2-cli chain score

Diagnostic

Server info

Returns the REST server components versions.

Options

--profile <profile>  - (Optional) Select between your profiles, by providing a profile name.

Command

nem2-cli diagnostic serverInfo

Storage

Returns diagnostic information about the node storage.

Options

--profile <profile>  - (Optional) Select between your profiles, by providing a profile name.

Command

nem2-cli diagnostic storage

Metadata

Account

Returns metadata entries from an account.

Options

--profile <profile>     - (Optional) Select between your profiles, by providing a profile name.
-a, --address <address> - Account address.

Command

nem2-cli metadata account --address SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54

Mosaic

Returns metadata entries from a mosaic.

Options

--profile <profile>        - (Optional) Select between your profiles, by providing a profile name.
-m, --mosaic-id <mosaicId> - Mosaic id in hexadecimal format.

Command

nem2-cli metadata mosaic --mosaic-id 71415AC19C818709

Namespace

Returns metadata entries from a namespace.

Options

--profile <profile>                  - (Optional) Select between your profiles, by providing a profile name.
-n, --namespace-name <namespaceName> - Namespace name.

Command

nem2-cli metadata namespace --namespace-name foo

Monitor

The NEM2 command line interface has a set of monitoring commands to track events in the NEM blockchain.

Block

Monitors new confirmed blocks harvested in the blockchain.

Options

--profile <profile> - (Optional) Select between your profiles, by providing a profile name.

Command

nem2-cli monitor block

Confirmed transactions

Monitors new confirmed transactions signed or received by an account.

Options

--profile <profile>     - (Optional) Select between your profiles, by providing a profile name.
-a, --address <address> - Account address.

Command

nem2-cli monitor confirmed --address SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54

Unconfirmed transactions

Monitors new unconfirmed transactions signed or received by an account.

Options

--profile <profile>     - (Optional) Select between your profiles, by providing a profile name.
-a, --address <address> - Account address.

Command

nem2-cli monitor unconfirmed --address SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54

Aggregate bonded transactions

Monitors new aggregate transactions with missing signatures added to an account.

Options

--profile <profile>     - (Optional) Select between your profiles, by providing a profile name.
-a, --address <address> - Account address.

Command

nem2-cli monitor aggregatebonded --address SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54

Transaction status

Monitors account validation errors.

Options

--profile <profile>     - (Optional) Select between your profiles, by providing a profile name.
-a, --address <address> - Account address.

Command

nem2-cli monitor status --address SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54

Mosaic

Info

Gets information from a mosaic.

Options

--profile <profile>            - (Optional) Select between your profiles, by providing a profile name.
-m, --mosaic-id <mosaicId>     - Mosaic id in hexadecimal format.

Command

nem2-cli mosaic info --mosaic-id 71415AC19C818709

Namespace

Info

Gets information from a namespace.

Options

--profile <profile> - (Optional) Select between your profiles, by providing a profile name.
-n, --name <name>   - Namespace name.
-h, --hex <hex>     - Namespace id in hexadecimal.

Command

nem2-cli namespace info --name foo

Owned

Gets all the namespaces owned by an account.

Options

--profile <profile>     - (Optional) Select between your profiles, by providing a profile name.
-n, --name <name>       - Namespace name.
-h, --hex <hex>         - Namespace id in hexadecimal.
-a, --address <address> - Address

Command

nem2-cli namespace owned --address SCEKUG-H2IJBF-7JZRNK-ECMW52-E66SZ6-ODLB4W-NI7K

Alias

Get mosaicId or address behind an namespace.

Options

--profile <profile> - (Optional) Select between your profiles, by providing a profile name.
-n, --name <name>   - Namespace name.

Command

nem2-cli namespace alias --name cat.currency

Transaction

Transactions are signed with the profiles configured with nem2-cli profile create.

Transaction info

Returns transaction information given a hash.

Options

--profile <profile> - (Optional) Select between your profiles, by providing a profile name.
-h, --hash <hash>   - Transaction hash.

Command

nem2-cli transaction info --hash AF92D0A1DC40F786DF455A54F3754E6ACBCEC1B590646404B5ACC85403A92690

Transaction Status

Gets the confirmation status of a transaction.

Options

--profile <profile> - (Optional) Select between your profiles, by providing a profile name.
-h, --hash <hash>   - Transaction hash.

Command

nem2-cli transaction status --hash AF92D0A1DC40F786DF455A54F3754E6ACBCEC1B590646404B5ACC85403A92690

AccountLinkTransaction

Delegates the account importance to a proxy account.

Options

--profile <profile>          - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>       - Maximum fee you want to pay to announce this transaction.
-p, --public-key <publicKey> - Remote account public key.
-a, --action <action>        - Alias action (1: Link, 0: Unlink).

Command

nem2-cli transaction accountlink --public-key 07A87708BF791A69EB715E466935705E7C98141FBA9EB132644C74FBA467B197 --action 1

CosignatureTransaction

Cosigns and announces an AggregateBondedTransaction.

Options

-h, --hash <hash>       - AggregateBondedTransaction hash to be signed.

Command

nem2-cli transaction cosign --hash A6A374E66B32A3D5133018EFA9CD6E3169C8EEA339F7CCBE29C47D07086E068C

MosaicDefinitionTransaction

Creates a new mosaic.

Options

--profile <profile>               - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>            - Maximum fee you want to pay to announce this transaction.
-a, --amount <amount>             - Initial supply of mosaics.
-t, --transferable                - (Optional)  Mosaic transferable.
-s, --supply-mutable              - (Optional)  Mosaic supply mutable.
-r, --restrictable                - (Optional) Mosaic restrictable.
-d, --divisibility <divisibility> - Mosaic divisibility, from 0 to 6.
-u, --duration <duration>         - Mosaic duration in amount of blocks.
-n, --non-expiring                - (Optional) Mosaic non-expiring.

Command

nem2-cli transaction mosaic --amount 1000000 --divisibility 0 --non-expiring --transferable --supply-mutable --restrictable

MosaicSupplyChangeTransaction

Changes a mosaic mosaic.

Options

--profile <profile>        - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>     - Maximum fee you want to pay to announce this transaction.
-a, --action <action>      - Mosaic supply change action (1: Increase, 0: Decrease).
-m, --mosaic-id <mosaicId> - Mosaic id in hexadecimal format.
-d, --delta <delta>        - Atomic amount of supply change.

Command

nem2-cli transaction mosaicsupplychange --action 1 --mosaic-id 7cdf3b117a3c40cc --delta 100000

NamespaceRegistrationTransaction

Registers a namespace.

Options

--profile <profile>            - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>         - Maximum fee you want to pay to announce this transaction.
-n, --name <name>              - Namespace name.
-r, --rootnamespace            - Root namespace.
-s, --subnamespace             - Sub namespace.
-d, --duration <duration>      - Duration (use it with --rootnamespace).
-p, --parent-name <parentName> - Parent namespace name (use it with --subnamespace).

Command

Register a root namespace:

nem2-cli transaction namespace --name foo --rootnamespace --duration 1000

Register a subnamespace:

nem2-cli transaction namespace --subnamespace --parent-name foo --name bar

AddressAliasTransaction

Links a namespace to an address.

Options

--profile <profile>         - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>      - Maximum fee you want to pay to announce this transaction.
-a, --action <action>       - Alias action (1: Link, 0: Unlink).
-a, --address <address>     - Account address.
-n, --namespace <namespace> - Namespace name.

Command

nem2-cli transaction addressalias --action 1 --mosaic 7cdf3b117a3c40cc --address SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54

MosaicAliasTransaction

Links a namespace to a mosaic.

Options

--profile <profile>         - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>      - Maximum fee you want to pay to announce this transaction.
-a, --action <action>       - Alias action (1: Link, 0: Unlink).
-m, --mosaic-id <mosaicId>  - Mosaic id in in hexadecimal format.
-n, --namespace <namespace> - Namespace name.

Command

nem2-cli transaction mosaicalias --action 1 --mosaic 7cdf3b117a3c40cc --namespace foo

MultisigModificationAccountTransaction

Create or modify a multisig account.

Note

The command only supports to add or remove one account as a cosignatory at a time.

Options

--profile <profile>                                          - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>                                       - Maximum fee you want to pay to announce the transaction.
-F, --max-fee-hash-lock <maxFeeHashLock>                     - Maximum fee you want to pay to announce the hash lock transaction.
-D, --duration <duration>                                    - Hash lock duration expressed in blocks. [480]
-L, --amount <amount>                                        - Amounts of mosaics to lock. [10]
-R, --min-removal-delta <minRemovalDelta>                    - (Optional) Number of signatures needed to remove a cosignatory.  [0]
-A, --min-approval-delta <minApprovalDelta>                  - (Optional) Number of signatures needed to approve a transaction. [0]
-a, --action <action>                                        - Modification Action (1: Add, 0: Remove).
-p, --cosignatory-public-key <cosignatoryPublicKey>          - Cosignatory account public key.
-m, --multisig-account-public-key <multisigAccountPublicKey> - Multisig account public key.

Command

nem2-cli transaction multisigmodification --min-approval-delta 1 --min-removal-delta 1 --action 1 --cosignatory-public-key FF8765F86312A79219D7BC2E0E3506A83A0E1D6D46A9C6998749A90E145FC96C --multisig-account-public-key 3AD5E02999457F8DBC645EE1F6316110509CC3E0DC7A6EAD4F84852086278838

SecretLockTransaction

Announces a SecretLockTransaction.

Options

--profile <profile>                        - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>                     - Maximum fee you want to pay to announce this transaction.
-m, --mosaic-id <mosaicId>                 - Locked mosaic identifier.
-a, --amount <amount>                      - Amount of mosaic units to lock.
-d, --duration <duration>                  - Number of blocks for which a lock should be valid. Duration is allowed to lie up to 30 days. If reached, the mosaics will be returned to the initiator.
-s, --secret <secret>                      - Proof hashed in hexadecimal format.
-H, --hash-algorithm <hashAlgorithm>       - Algorithm used to hash the proof (0: Op_Sha3_256, 1: Op_Keccak_256, 2: Op_Hash_160, 3: Op_Hash_256).
-r, --recipient-address <recipientAddress> - Address that receives the funds once unlocked.

Command

nem2-cli transaction secretlock --secret BFD12D3F14460FA9B7CE0B209FCAF37FFFAED56E2925E595ACD569B6D29FA2CF --hash-algorithm 0 --mosaic-id 0ADA87EF8D08E6C5 --amount 100 --duration 400 --recipient-address SATXKQ-QSWIMT-3S32BA-IEMZXD-P4HHUA-LDEYPL-EAZY

SecretProofTransaction

Announces a SecretProofTransaction.

Options

--profile <profile>                        - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>                     - Maximum fee you want to pay to announce this transaction.
-s, --secret <secret>                      - Proof hashed in hexadecimal.
-p, --proof <proof>                        - Original random set of bytes in hexadecimal.
-H, --hash-algorithm <hashAlgorithm>       - Algorithm used to hash the proof (0: Op_Sha3_256, 1: Op_Keccak_256, 2: Op_Hash_160, 3: Op_Hash_256).
-r, --recipient-address <recipientAddress> - Address that receives the funds once unlocked.

Command

nem2-cli transaction secretproof --secret BFD12D3F14460FA9B7CE0B209FCAF37FFFAED56E2925E595ACD569B6D29FA2CF --proof 519548b5cfb82fc2899f --hash-algorithm 0 --recipient-address SATXKQ-QSWIMT-3S32BA-IEMZXD-P4HHUA-LDEYPL-EAZY

AccountAddressRestrictionTransaction

Allow or block incoming and outgoing transactions for a given a set of addresses.

Options

--profile <profile>                                - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>                             - Maximum fee you want to pay to announce this transaction.
-t, --restriction-type <restrictionType>           - Restriction type (allow, block).
-d, --restriction-direction <restrictionDirection> - Restriction direction (incoming, outgoing).
-a, --modification-action <modificationAction>     - Modification action. (1: Add, 0: Remove).
-v, --value <value>                                - Address to allow / block.

Command

nem2-cli transaction accountaddressrestriction --restriction-type allow --restriction-direction incoming --modification-action 1 --value SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54

AccountMosaicRestrictionTransaction

Allow or block incoming transactions containing a given set of mosaics.

Options

--profile <profile>                                - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>                             - Maximum fee you want to pay to announce this transaction.
-t, --restriction-type <restrictionType>           - Restriction type (allow, block).
-a, --modification-action <modificationAction>     - Modification action. (1: Add, 0: Remove).
-v, --value <value>                                - Mosaic to allow / block.

Command

nem2-cli transaction accountmosaicrestriction --restriction-type allow --modification-action 1 --value 4F2F242FA35763F6

AccountOperationRestrictionTransaction

Allow or block outgoing transactions by transaction type.

Options

--profile <profile>                                - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>                             - Maximum fee you want to pay to announce this transaction.
-t, --restriction-type <restrictionType>           - Restriction type (allow, block).
-d, --restriction-direction <restrictionDirection> - Restriction direction (incoming, outgoing).
-a, --modification-action <modificationAction>     - Modification action. (1: Add, 0: Remove).
-v, --value <value>                                - Transaction type formatted as hex.

Command

nem2-cli transaction accountoperationrestriction --restriction-type block --restriction-direction outgoing --modification-action 1 --value 414C

TransferTransaction

Announces a TransferTransaction to an account exchanging value and/or data. For this transaction provide recipient, message and mosaics.

You can send multiple mosaics splitting them with a comma, e.g: @cat.currency::10000000,7cdf3b117a3c40cc::10. The mosaic amount after :: is in absolute value so 1 @cat.currency is 1000000 (divisibility 6).

Options

--profile <profile>         - (Optional) Select between your profiles, by providing a profile name.
-f, --max-fee <maxFee>      - Maximum fee you want to pay to announce this transaction.
-r, --recipient <recipient> - Recipient address or @alias.
-m, --message <message>     - Transaction message.
-c, --mosaics <mosaics>     - Mosaic to transfer in the format (mosaicId(hex)|@aliasName)::absoluteAmount. Add multiple mosaics with commas.
-e, --encrypted                                 - (Optional) Send an encrypted message. If you set this value, you should set the value of 'recipientPublicKey' as well).
-p, --recipient-public-key <recipientPublicKey> - (Optional) The recipient public key in an encrypted message.

Command

 nem2-cli transaction transfer --recipient SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54 --mosaics @cat.currency::10000000 --message "Welcome to NEM"

Restriction

Get account restrictions

Returns the account restrictions attached to an address.

Options

--profile <profile>     - (Optional) Select between your profiles, by providing a profile name.
-a, --address <address> - Account address

Command

nem2-cli restriction account --address SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54

Get mosaic global restrictions

Returns the global restrictions assigned to a mosaic.

Options

--profile <profile>        - (Optional) Select between your profiles, by providing a profile name.
-m, --mosaic-id <mosaicId> - Mosaic id in hexadecimal format.

Command

nem2-cli restriction mosaicglobal --mosaic-id 71415AC19C818709

Get mosaic address restrictions

Returns the mosaic address restrictions assigned to an address.

Options

--profile <profile>        - (Optional) Select between your profiles, by providing a profile name.
-m, --mosaic-id <mosaicId> - Mosaic id in hexadecimal format.
-a, --address <address>    - Account address.

Command

nem2-cli restriction mosaicaddress --mosaic-id 71415AC19C818709 --address SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54