Cover photo

How to make multiple transaction on Cosmos?

Get a small guidance how to put multimple transaction in one on cosmos. Prepared by BlvckStake team for DVS school group 3.2 🤝

The logic would be as follows: - Step 1: Create transaction in “generate-only” mode & save .json file of this transaction. - Step 2: Open .json file and edit array called messages by adding more objects to it. - Step 3: Sign edited .json file. - Step 4: Boardcast this signed .json file to comlete transaction.

Detailed Step-by-Step Insturction:

  • Step 1:

    We create a transaction without signing or sending it and save the output to a JSON file.

    Syntax:

    gaiad tx bank send [from_key_or_address] [to_address] [amount]uatom --fees 1000uatom --chain-id [your_chain_id] --generate-only > [file_name.json]

    - [from_key_or_address] - Sender's moniker or address.

    - [to_address] - The address of the recipient.

    - [amount] - The amount of tokens to send (1 atom = 1 000 000 uatom).

    - [your_chain_id] - The ID of your blockchain, in our case you can find it out with: cat ~/.gaia/config/genesis.json | grep -m 1 "chain_id"

    - [file_name.json] - An arbitrary file name with .json extension.

EXAMPLE:

gaiad tx bank send cosmos1ymyqkw6gu5fus4llcex996yu9997chv80ukcm9 cosmos19t3jghm48786fucdjq3hgzyg0qucrrtyech32n 1000uatom --fees 1000uatom --chain-id school-testnet-3 --generate-only > tx.json

  • Step 2:

    Edit the JSON file with the transaction, add the required number of transactions.

    2.1 By default the output in JSON file will not be structured, for convenience you will need to install any text editor that supports JSON format (Notepad++; Visual Studio Code; Sublime Text; Atom). In our case we use Notepad++ ("https://notepad-plus-plus.org/downloads/"), in combination with the Json Tools plugin, which you can install right inside the application in the Plugins tab. We need this plugin to convert our code into a structured, readable form.

    2.2 Move to the directory with the transaction file and read its content with the command: cat tx.json. Copy and paste its output into our editor, then go to our plugin and press Plugins>Json Tools>Pretty-print current JSON file

Plugins>Json Tools>Pretty-print current JSON file
Plugins>Json Tools>Pretty-print current JSON file

2.3 Copy the object, as shown in the screenshot and duplicate it the required number of times. Make sure you put a comma in the syntax between objects, don't put a comma only after the last object. Edit duplicated objects, changing the recipient addresses and the number of tokens to send.

Copy the object.
Copy the object.
A comma.
A comma.
Edit duplicated objects.
Edit duplicated objects.

2.4 Copy the edited transaction and paste it back into our file on the server or create a new one. I will create a new file with the transaction using the command:

nano tx_ready.json

Let's paste the contents of the clipboard (Ctrl+Shift+V) and save the file (Ctrl+X > Y > Enter).

  • Step 3:

    Sign the modified transaction file. Syntax:

    gaiad tx sign [file_name_ready.json] --from [from_key_or_address] --chain-id [your_chain_id] --output-document [file_name.json]

    - [file_name_ready.json] - JSON file with the final transaction to be sent.

    - [from_key_or_address] - Moniker or address of purse from which we sign transaction.

    - [your_chain_id] - The ID of your blockchain. In our case you can get it with the command: cat ~/.gaia/config/genesis.json | grep -m 1 "chain_id"

    - [your_chain_id] - The ID of your blockchain, in our case you can find it out with: cat ~/.gaia/config/genesis.json | grep -m 1 "chain_id"

    - [file_name.json] - An arbitrary file name for the signed transaction with the .json extension.

EXAMPLE:

gaiad tx sign tx_ready.json --from BlvckStake --chain-id school-testnet-3 --output-document signed.json

  • Step 4:

    Send the transaction. Syntax:

    gaiad tx broadcast [file_name_signed.json]

    - [file_name_signed.json] - Path to file with signed transaction.

EXAMPLE:

gaiad tx broadcast signed.json

We hope it will help you to get extra point during our studing💪 With Love by BlvckStake❤️ Follow us on Twitter: BlvckStake.

#WAGMI