Skip to main content

💸 Transaction Guide

In Cedra, every action that changes the blockchain state happens through a transaction. Unlike Ethereum where you can send ETH directly to an address, Cedra requires all state changes to go through entry functions - think of them as public APIs exposed by smart contracts.

Every transaction in Cedra contains:

  • Sender: Who's initiating the transaction
  • Sequence Number: Prevents replay attacks (must be exact)
  • Payload: What function to call with what arguments
  • Gas Configuration: How much you're willing to pay
  • Expiration: When the transaction becomes invalid

💰 Sending Your First Transaction

Here's the complete flow of sending tokens on Cedra. This is the most common transaction you'll perform:

use cedra_sdk::{
coin_client::CoinClient,
rest_client::Client,
types::LocalAccount,
};

// Connect to the network
let client = Client::new("https://testnet.cedra.dev");
let coin_client = CoinClient::new(&client);

// Load your account (must have CED for gas)
let mut alice = load_account()?;
let bob_address = "0x123..."; // Recipient

// Transfer 0.01 CED (1,000,000 Octas)
let txn_hash = coin_client
.transfer(&mut alice, bob_address, 1_000_000, None)
.await?;

// Wait for confirmation
client.wait_for_transaction(&txn_hash).await?;

println!("Sent 0.01 CED to Bob");
println!("Transaction: 0x{}", txn_hash);

That's it. The SDK handled fetching Alice's sequence number, estimating gas, setting expiration, signing, and waiting for confirmation. The transfer function is a convenience wrapper around the more general transaction building process.

Notice we specify the amount in Octas (Cedra's smallest unit). Just like Wei in Ethereum, 1 CED = 100,000,000 Octas. Always use the smallest unit to avoid floating-point precision issues.

⚡ Gas and Safety

Gas in Cedra represents computational work, just like Ethereum. However, there are crucial differences:

  • Multi-token payment: You can pay gas in multiple tokens, not just CED
  • Predictable costs: Entry functions have consistent gas usage
  • Safety margin: The SDK automatically adds a 20% buffer to gas estimates
  • Refunds: Unused gas is automatically refunded

Most simple operations use 5-10 gas units. Complex DeFi operations might use hundreds or thousands. The network sets a base gas price.

Always simulate transactions in production. It's free, prevents costly failures, and gives you accurate gas estimates. Think of simulation as your test run before the real thing.

📜 Working with Smart Contracts

Every smart contract interaction follows the same pattern as transfers. You specify which function to call and provide the necessary arguments. The complexity comes from knowing what functions are available and what they expect.

🔄 Transaction Lifecycle

Understanding what happens after you submit a transaction helps you build better error handling:

  1. Building: Construct the transaction with all parameters
  2. Signing: Use your private key to authorize it
  3. Submission: Send to a Cedra node
  4. Validation: Node checks signature and sequence number
  5. Execution: Smart contract runs, state changes applied
  6. Confirmation: Transaction included in a block

🚀 Next Steps

Master transaction development and explore advanced Cedra features:

Build on Your Knowledge

Smart Contract Development

Real-World Applications

Development Tools