Method Signature
align.blockchain.wallets.sendNativeToken(
wallet: Wallet,
to: string,
amount: string,
network: Network
): Promise<Transaction>
Parameters
The sender’s wallet object (with private key)
Amount to send (e.g., "0.1" for 0.1 ETH/MATIC)
Network: ethereum, polygon, base, arbitrum, optimism
Returns
Transaction status: pending, confirmed, failed
Examples
import Align from "@tolbel/align";
const align = new Align({
apiKey: process.env.ALIGN_API_KEY!,
environment: "sandbox",
});
// Create or import a wallet
const wallet = await align.blockchain.wallets.createFromPrivateKey(
process.env.PRIVATE_KEY!
);
// Send 0.1 MATIC
const tx = await align.blockchain.wallets.sendNativeToken(
wallet,
"0xRecipientAddress...",
"0.1",
"polygon"
);
console.log(`TX Hash: ${tx.hash}`);
// Wait for confirmation
const receipt = await align.blockchain.transactions.waitForConfirmation(
tx.hash,
"polygon"
);
console.log(`Confirmed in block ${receipt.blockNumber}`);
const wallet = await align.blockchain.wallets.createFromPrivateKey(
process.env.PRIVATE_KEY
);
const tx = await align.blockchain.wallets.sendNativeToken(
wallet,
"0xRecipient...",
"0.1",
"polygon"
);
console.log("TX Hash:", tx.hash);
Check Balance Before Send
const balance = await align.blockchain.wallets.getBalance(
wallet.address,
"polygon"
);
const sendAmount = "0.1";
const estimatedGas = 0.001; // Approximate gas cost
if (parseFloat(balance) < parseFloat(sendAmount) + estimatedGas) {
throw new Error("Insufficient balance");
}
await align.blockchain.wallets.sendNativeToken(
wallet,
to,
sendAmount,
"polygon"
);
Ensure the wallet has sufficient balance for both the transfer amount and gas
fees.