Skip to main content
Sending transactions using InitiaJS is straightforward. First, import the necessary classes and functions.
Next, set up your environment variables. You will need the following:
  • MNEMONIC: The mnemonic of the account that will be sending the transaction.
  • REST_URL: The URL of the Initia REST.
  • GAS_PRICES: The gas prices for the transaction.
  • SENDER_ADDRESS: The address of the account that will be sending the transaction.
  • RECIPIENT_ADDRESS: The address of the account that will be receiving the transaction.
  • AMOUNT: The amount of tokens to send.
You can then use these variables to ultimately create the wallet client, as well as the sendMsg object. Since for this example you’re making a token transfer, we’ll use the MsgSend object. But the SDK provides many other message types for different actions related to staking, governance, and more.
Next, create the function to send the transaction.
  • First, create the transaction by calling wallet.createAndSignTx. This function takes in the raw message object, signs it using the wallet, and returns a signed transaction object.
  • Then, broadcast the transaction by calling restClient.tx.broadcast. This function takes in the signed transaction object and broadcasts it to the network.
Finally, call the function to send the transaction.
If you then run the script using npx ts-node src/sending-transactions.ts, you should see an output similar to the following:

Full Example

src/sending-transactions.ts