Transactions
Sending Transactions
Sending transactions using InitiaJS is straightforward. First, we need to import the necessary classes and functions.
Next, we need to set up our environment variables. We will need the following:
MNEMONIC
: The mnemonic of the account that will be sending the transaction.LCD_URL
: The URL of the Initia LCD.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.
Finally, we can create the function to send the transaction.
- We first create the transaction by calling
wallet.createAndSignTx
. This function takes in the raw message object, signs it using thewallet
, and returns a signed transaction object. - We then broadcast the transaction by calling
lcd.tx.broadcast
. This function takes in the signed transaction object and broadcasts it to the network.
Finally, we can 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
Was this page helpful?