Skip to main content

Basic Transactions

As of writing, there are 4 main types of transactions:

In this section, we will explore the following:

Send ADA to Addresses

You can chain tx.sendLovelace() to send to multiple recipients. For example:

import { Transaction } from "@meshsdk/core";

const tx = new Transaction({ initiator: wallet })
.sendLovelace(
"addr_test1vpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0c7e4cxr",
"1000000"
)
.sendLovelace("ANOTHER ADDRESS HERE", "1500000");

const unsignedTx = await tx.build();
const signedTx = await wallet.signTx(unsignedTx);
const txHash = await wallet.submitTx(signedTx);

Try demo

Send Multiple Assets to Addresses

We can chain a series of tx.sendAssets() and tx.sendLovelace() to send multiple assets to multiple recipients. For example:

import { Transaction, Asset } from "@meshsdk/core";

const tx = new Transaction({ initiator: wallet })
.sendLovelace(
"addr_test1vpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0c7e4cxr",
"1000000"
)
.sendAssets(
"addr_test1vpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0c7e4cxr",
[
{
unit: "64af286e2ad0df4de2e7de15f8ff5b3d27faecf4ab2757056d860a424d657368546f6b656e",
quantity: "1",
},
]
)
.sendLovelace("ANOTHER ADDRESS HERE", "1500000");

const unsignedTx = await tx.build();
const signedTx = await wallet.signTx(unsignedTx);
const txHash = await wallet.submitTx(signedTx);

Try demo

Send Assets to Handler

We can get the ADA Handle's address with any blockchain providers and calling the fetchHandleAddress() function.

For instance, lets send some lovelace to $jingles:

import { KoiosProvider, Transaction } from "@meshsdk/core";

const koios = new KoiosProvider("api");

const tx = new Transaction({ initiator: wallet })
.sendLovelace(
await koios.fetchHandleAddress("jingles"),
"1000000"
);

const unsignedTx = await tx.build();
const signedTx = await wallet.signTx(unsignedTx);
const txHash = await wallet.submitTx(signedTx);

Send tokens and stable coins to addresses

Like sendLovelace(), we can chain sendToken() along side tx.sendLovelace() to send multiple assets to multiple recipients.

For instance, lets send some DJED to ADA to jingles:

import { Transaction } from '@meshsdk/core';

const koios = new KoiosProvider("api");
const address = await koios.fetchHandleAddress("jingles");

const tx = new Transaction({ initiator: wallet })
.sendToken(
address,
'DJED',
'1000000'
)
.sendLovelace(
address,
"1000000"
);

const unsignedTx = await tx.build();
const signedTx = await wallet.signTx(unsignedTx);
const txHash = await wallet.submitTx(signedTx);

Check out the Mesh Playground for live demo and full explanation.