Skip to main content

Send Your First Transaction

This tutorial walks you through sending your first transaction on the ACDC network. We will use the Delta chain for this example, as it is the account-based chain best suited for standard transfers.

Prerequisites

  • Node.js 18+ installed
  • An ACDC wallet with testnet tokens
  • Basic JavaScript/TypeScript knowledge

Step 1: Set Up Your Project

Create a new project and install the SDK:

mkdir acdc-tutorial
cd acdc-tutorial
npm init -y
npm install @acdc/sdk

Create a file called send-tx.js:

// send-tx.js
const { AcdcClient, Wallet, parseUnits, formatUnits } = require('@acdc/sdk');

async function main() {
// We'll add code here
}

main().catch(console.error);

Step 2: Connect to the Network

First, connect to the Delta testnet:

const { AcdcClient, Wallet, parseUnits, formatUnits } = require('@acdc/sdk');

async function main() {
// Connect to Delta testnet
const client = new AcdcClient({
chain: 'delta',
network: 'testnet'
});

console.log('Connected to Delta testnet');

// Get chain info
const info = await client.getChainInfo();
console.log(`Current block: ${info.blockHeight}`);
}

main().catch(console.error);

Run it:

node send-tx.js

You should see output like:

Connected to Delta testnet
Current block: 1234567

Step 3: Create or Import a Wallet

For testing, you can generate a new wallet or import an existing one:

const { AcdcClient, Wallet, parseUnits, formatUnits } = require('@acdc/sdk');

async function main() {
const client = new AcdcClient({
chain: 'delta',
network: 'testnet'
});

// Option 1: Generate new wallet
const wallet = Wallet.create();
console.log('New wallet address:', wallet.address);
console.log('Mnemonic (save this!):', wallet.mnemonic);

// Option 2: Import from mnemonic
// const wallet = Wallet.fromMnemonic('your twelve word mnemonic phrase here');

// Option 3: Import from private key
// const wallet = Wallet.fromPrivateKey('0xYOUR_PRIVATE_KEY');

// Connect wallet to client
const signer = wallet.connect(client);

// Check balance
const balance = await client.getBalance(wallet.address);
console.log(`Balance: ${balance.formatted} ACDC`);
}

main().catch(console.error);
caution

Never share your mnemonic or private key. For testing, use a dedicated testnet wallet.

Step 4: Get Testnet Tokens

If your balance is zero, get testnet tokens from the faucet:

  1. Visit the ACDC Testnet Faucet
  2. Enter your wallet address
  3. Request testnet tokens

Wait a few seconds, then re-run your script to verify the balance.

Step 5: Send a Transaction

Now you are ready to send a transaction:

const { AcdcClient, Wallet, parseUnits, formatUnits } = require('@acdc/sdk');

async function main() {
const client = new AcdcClient({
chain: 'delta',
network: 'testnet'
});

// Import your funded wallet
const wallet = Wallet.fromMnemonic('your twelve word mnemonic phrase here');
const signer = wallet.connect(client);

console.log('Sender:', wallet.address);

// Check balance before
const balanceBefore = await client.getBalance(wallet.address);
console.log(`Balance before: ${balanceBefore.formatted} ACDC`);

// Recipient address (use your own or another test address)
const recipient = 'dx1recipient_address_here';

// Amount to send (0.1 ACDC)
const amount = parseUnits('0.1', 18);

console.log(`\nSending 0.1 ACDC to ${recipient}...`);

// Send transaction
const tx = await signer.sendTransaction({
to: recipient,
value: amount
});

console.log(`Transaction hash: ${tx.hash}`);
console.log('Waiting for confirmation...');

// Wait for confirmation
const receipt = await tx.wait();

console.log(`\nConfirmed in block ${receipt.blockNumber}`);
console.log(`Gas used: ${receipt.gasUsed}`);
console.log(`Status: ${receipt.status === 1 ? 'Success' : 'Failed'}`);

// Check balance after
const balanceAfter = await client.getBalance(wallet.address);
console.log(`\nBalance after: ${balanceAfter.formatted} ACDC`);
}

main().catch(console.error);

Run it:

node send-tx.js

Expected output:

Sender: dx1abc123...
Balance before: 10.0 ACDC

Sending 0.1 ACDC to dx1recipient...
Transaction hash: 0x123abc...
Waiting for confirmation...

Confirmed in block 1234568
Gas used: 21000
Status: Success

Balance after: 9.8999... ACDC

Step 6: Verify on Block Explorer

You can verify your transaction on the block explorer:

  1. Go to Delta Testnet Explorer
  2. Search for your transaction hash
  3. View transaction details

Understanding the Transaction

Let's break down what happened:

// parseUnits converts human-readable amounts to base units (wei)
// 0.1 ACDC = 100000000000000000 wei (18 decimal places)
const amount = parseUnits('0.1', 18);

// Create and send the transaction
const tx = await signer.sendTransaction({
to: recipient, // Destination address
value: amount // Amount in wei
});

// tx.hash is available immediately (transaction is broadcast)
console.log(`Transaction hash: ${tx.hash}`);

// Wait for mining and confirmation
const receipt = await tx.wait();

// receipt contains confirmation details
// - blockNumber: which block included the transaction
// - gasUsed: actual gas consumed
// - status: 1 = success, 0 = failure

Handling Errors

Add error handling for common issues:

async function main() {
try {
// ... your code ...

const tx = await signer.sendTransaction({
to: recipient,
value: amount
});

const receipt = await tx.wait();

} catch (error) {
if (error.code === 'INSUFFICIENT_FUNDS') {
console.error('Not enough ACDC to send this transaction');
console.error('Request tokens from the faucet');
} else if (error.code === 'NONCE_TOO_LOW') {
console.error('Transaction nonce conflict - try again');
} else if (error.code === 'NETWORK_ERROR') {
console.error('Network connection issue - check your internet');
} else {
console.error('Transaction failed:', error.message);
}
process.exit(1);
}
}

Complete Example

Here is the complete, production-ready code:

// send-tx.js
const { AcdcClient, Wallet, parseUnits, formatUnits } = require('@acdc/sdk');

async function main() {
// Configuration
const NETWORK = 'testnet'; // Change to 'mainnet' for real transactions
const MNEMONIC = process.env.ACDC_MNEMONIC; // Set via environment variable
const RECIPIENT = process.env.RECIPIENT || 'dx1...';
const AMOUNT = process.env.AMOUNT || '0.1';

if (!MNEMONIC) {
console.error('Set ACDC_MNEMONIC environment variable');
process.exit(1);
}

// Connect
const client = new AcdcClient({
chain: 'delta',
network: NETWORK
});

const wallet = Wallet.fromMnemonic(MNEMONIC);
const signer = wallet.connect(client);

console.log(`Network: Delta ${NETWORK}`);
console.log(`Sender: ${wallet.address}`);

// Check balance
const balance = await client.getBalance(wallet.address);
const amountWei = parseUnits(AMOUNT, 18);

if (balance.raw < amountWei) {
console.error(`Insufficient balance: ${balance.formatted} ACDC`);
console.error(`Required: ${AMOUNT} ACDC + gas`);
process.exit(1);
}

console.log(`Balance: ${balance.formatted} ACDC`);
console.log(`\nSending ${AMOUNT} ACDC to ${RECIPIENT}...`);

try {
const tx = await signer.sendTransaction({
to: RECIPIENT,
value: amountWei
});

console.log(`TX Hash: ${tx.hash}`);
console.log('Waiting for confirmation...');

const receipt = await tx.wait(1); // Wait for 1 confirmation

console.log(`\nTransaction confirmed!`);
console.log(`Block: ${receipt.blockNumber}`);
console.log(`Gas used: ${receipt.gasUsed}`);

const newBalance = await client.getBalance(wallet.address);
console.log(`New balance: ${newBalance.formatted} ACDC`);

} catch (error) {
console.error('Transaction failed:', error.message);
process.exit(1);
}
}

main();

Run with environment variables:

ACDC_MNEMONIC="your mnemonic here" \
RECIPIENT="dx1recipient..." \
AMOUNT="0.1" \
node send-tx.js

Next Steps

Now that you have sent your first transaction, explore these tutorials: