DEV Community

Sergio Antonio Felix Sanchez
Sergio Antonio Felix Sanchez

Posted on

Zero-to-One: Deploying Your First Smart Contract on Base

Why Base?

Base is an L2 on Ethereum that's cheap ($0.001-0.01/tx) and fast (1 second blocks). Perfect for micro-payment use cases like x402.

What We'll Build

A simple payment gateway that accepts USDC and triggers an API response.

Prerequisites

  • Node.js
  • viem (ethereum library)
  • A wallet with some ETH on Base for gas

The Contract

// Simple payment verification
contract PaymentGateway {
    IERC20 public usdc;
    address public payTo;
    uint256 public price;

    function pay() external {
        usdc.transferFrom(msg.sender, payTo, price);
        emit PaymentReceived(msg.sender, price);
    }
}
Enter fullscreen mode Exit fullscreen mode

Deployment

# Using viem + Base
npx wagmi init
# Deploy to Base Mainnet
npx hardhat run scripts/deploy --network base
Enter fullscreen mode Exit fullscreen mode

The API Integration

On the backend, verify the payment and process the request:

app.post('/api/service', async (req, res) => {
  const { txHash } = req.body;
  const verified = await verifyPayment(txHash);
  if (!verified) return res.status(402).json({ error: 'payment required' });
  const result = await processRequest(req.body);
  res.json(result);
});
Enter fullscreen mode Exit fullscreen mode

Cost

Deploying to Base: ~$0.50 in gas
Per transaction: ~$0.001 in gas
Per API call: $0.01 USDC + $0.001 gas = $0.011 total

Resources


Built on Base with ❀️

Top comments (0)