Skip to Content

Build a decentralized app with Solidity (Quickstart)

Build and deploy your first Solidity smart contract on Arbitrum with the Remix IDE, covering contract basics, wallet setup, and testnet deployment.

Request an update
Want to use Rust instead?

Head over to the Stylus quickstart if you'd like to use Rust instead of Solidity.

This quickstart is for web developers who want to start building decentralized applications using . It makes no assumptions about your prior experience with Ethereum, Arbitrum, or Solidity. Familiarity with Javascript and yarn is expected. If you're new to Ethereum, consider studying the Ethereum documentation before proceeding.

What we'll learn

In this tutorial we will learn:

  1. The basics of Ethereum vs. client/server architecture
  2. What is a Solidity smart contract
  3. How to compile and deploy a smart contract
  4. How to use an Ethereum wallet

We're going to build a digital cupcake vending machine using Solidity smart contracts1. This vending machine will follow two rules:

  1. The vending machine will distribute a cupcake to anyone who hasn't recently received one.
  2. The vending machine's rules can't be changed by anyone.

Here's the vending machine implemented with Javascript. To use it, enter a name in the form below and press the Cupcake please! button, you should see your cupcake balance go up.

Free Cupcakes

web2

Cupcake balance:0 (no name)

We can assume that this vending machine operates as we expect, but it's largely up to the centralized service provider that hosts it. In the case of a compromised cloud host:

  1. Our centralized service provider can deny access to particular users.
  2. A malicious actor can change the rules of the vending machine at any time, for example, to give their friends extra cupcakes.

Centralized third-party intermediaries represent a single point of failure that malicious actors can exploit. With a blockchain infrastructure such as Ethereum, we decentralize our vending machine's business logic and data, making this type of exploits nearly impossible.

This is Arbitrum's core value proposition to you, dear developer. Arbitrum makes it easy for you to deploy your vending machines to Ethereum's permissionless, , decentralized network of nodes2 while keeping costs low for you and your users.

Let's implement the "Web3" version of the above vending machine using Arbitrum.

Prerequisites

VS Code is the IDE we'll use to build our vending machine. See code.visualstudio.com to install.

We will use Metamask as the to interact with our vending machine. See metamask.io and click View MetaMask Web or OKX Wallet and click Connect Wallet to install.

Yarn is the package manager we'll use to install dependencies. See yarnpkg.com to install.

Foundry is the toolchain we'll use to compile and deploy our smart contract. See getfoundry.sh to install.

We'll address any remaining dependencies as we go.

Ethereum and Arbitrum in a nutshell

  • Ethereum
    • Ethereum is a decentralized network of nodes that use Ethereum's client software (like Offchain's Prysm to maintain a public data structure.
    • The data within Ethereum's blockchain data structure changes one transaction at a time.
    • are small programs that execute transactions according to predefined rules. Ethereum's nodes host and execute smart contracts.
    • You can use smart contracts to build decentralized apps that use Ethereum's network to process transactions and store data. Think of smart contracts as your app's backend
    • Apps let users carry their data and identity between applications without trusting centralized service providers.
    • People who run Ethereum validator nodes3 can earn ETH for processing and validating transactions on behalf of users and apps.
    • These transactions can be expensive when the network is under heavy load.
  • Arbitrum
    • Arbitrum is a finance-native platform providing infrastructure for building applications.
    • is a child chain that implements the . See the Arbitrum chains overview for a comparison of Arbitrum One, Nova, and the available testnets.
    • You can use Arbitrum One to build user-friendly apps with high throughput, low latency, and low transaction costs while inheriting Ethereum's high-security standards4.

Review the Javascript vending machine

Here's the vending machine implemented as a Javascript class:

class VendingMachine {
  // state variables = internal memory of the vending machine
  cupcakeBalances = {};
  cupcakeDistributionTimes = {};

  // Vend a cupcake to the caller
  giveCupcakeTo(userId) {
    if (this.cupcakeDistributionTimes[userId] === undefined) {
      this.cupcakeBalances[userId] = 0;
      this.cupcakeDistributionTimes[userId] = 0;
    }

    // Rule 1: The vending machine will distribute a cupcake to anyone who hasn't recently received one.
    const fiveSeconds = 5000;
    const userCanReceiveCupcake = this.cupcakeDistributionTimes[userId] + fiveSeconds <= Date.now();
    if (!userCanReceiveCupcake) {
      console.error('HTTP 429: Too Many Cupcakes (you must wait at least 5 seconds between cupcakes)');
      return false;
    }

    this.cupcakeBalances[userId]++;
    this.cupcakeDistributionTimes[userId] = Date.now();
    console.log(`Enjoy your cupcake, ${userId}!`);
    return true;
  }

  getCupcakeBalanceFor(userId) {
    return this.cupcakeBalances[userId];
  }
}

The VendingMachine class uses state variables and functions to implement predefined rules. This implementation is useful because it automates cupcake distribution, but there's a problem: it's hosted by a centralized server controlled by a third-party service provider.

Working web2 version

To use the Vending Machine (web2), copy and paste the HTML code below into a text document, then open it in your web browser.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Cupcake Vending Machine - Arbitrum Quickstart</title>
  <script src="https://cdn.ethers.io/lib/ethers-5.7.umd.min.js"></script>
  <style>
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      background: #0d1117;
      color: #e6edf3;
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 2rem 1rem;
    }

    h1 {
      font-size: 1.8rem;
      margin-bottom: 0.25rem;
      color: #58a6ff;
    }

    .subtitle {
      color: #8b949e;
      margin-bottom: 2rem;
      font-size: 0.95rem;
    }

    .machines {
      display: flex;
      gap: 2rem;
      flex-wrap: wrap;
      justify-content: center;
      width: 100%;
      max-width: 900px;
    }

    .vending-machine {
      background: #161b22;
      border: 1px solid #30363d;
      border-radius: 12px;
      padding: 1.5rem;
      width: 400px;
      display: flex;
      flex-direction: column;
      gap: 0.75rem;
    }

    .vending-machine h2 {
      font-size: 1.25rem;
      color: #e6edf3;
    }

    .vending-machine .badge {
      display: inline-block;
      font-size: 0.7rem;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      padding: 0.2em 0.6em;
      border-radius: 4px;
      width: fit-content;
    }

    .badge-web2 { background: #238636; color: #fff; }
    .badge-web3 { background: #1f6feb; color: #fff; }

    label {
      font-size: 0.85rem;
      color: #8b949e;
      font-weight: 500;
    }

    input[type="text"] {
      background: #0d1117;
      border: 1px solid #30363d;
      border-radius: 6px;
      padding: 0.6rem 0.75rem;
      color: #e6edf3;
      font-size: 0.9rem;
      outline: none;
      transition: border-color 0.2s;
    }

    input[type="text"]:focus {
      border-color: #58a6ff;
    }

    input[type="text"]::placeholder {
      color: #484f58;
    }

    .btn {
      padding: 0.6rem 1rem;
      border: none;
      border-radius: 6px;
      font-size: 0.9rem;
      font-weight: 600;
      cursor: pointer;
      transition: background 0.2s;
    }

    .btn-primary {
      background: #238636;
      color: #fff;
    }

    .btn-primary:hover { background: #2ea043; }

    .btn-secondary {
      background: transparent;
      color: #58a6ff;
      border: 1px solid #30363d;
    }

    .btn-secondary:hover { background: #161b22; border-color: #58a6ff; }

    .cupcake-display {
      font-size: 3rem;
      text-align: center;
      height: 4rem;
      line-height: 4rem;
      transition: opacity 0.3s;
    }

    .balance {
      display: flex;
      justify-content: space-between;
      align-items: center;
      background: #0d1117;
      border-radius: 6px;
      padding: 0.6rem 0.75rem;
      font-size: 0.9rem;
    }

    .balance-count {
      font-weight: 700;
      color: #58a6ff;
      font-size: 1.1rem;
    }

    .status {
      font-size: 0.8rem;
      min-height: 1.2rem;
      color: #f85149;
      text-align: center;
    }

    .status.success { color: #3fb950; }

    .hidden { display: none; }

    .actions {
      display: flex;
      gap: 0.5rem;
    }

    .actions .btn { flex: 1; }

    .description {
      font-size: 0.8rem;
      color: #8b949e;
      line-height: 1.4;
      border-left: 2px solid #30363d;
      padding-left: 0.75rem;
    }
  </style>
</head>
<body>

  <h1>Cupcake Vending Machine</h1>
  <p class="subtitle">From the Arbitrum Solidity + Remix Quickstart</p>

  <div class="machines">

    <!-- WEB2 Vending Machine -->
    <div class="vending-machine">
      <span class="badge badge-web2">Web2</span>
      <h2>Free Cupcakes</h2>
      <p class="description">Pure JavaScript vending machine. Business logic runs in your browser — no blockchain involved.</p>

      <label for="web2-name">Name</label>
      <input type="text" id="web2-name" placeholder="Enter name" />

      <div class="actions">
        <button class="btn btn-primary" id="web2-vend">Cupcake please!</button>
        <button class="btn btn-secondary" id="web2-refresh">Refresh balance</button>
      </div>

      <div class="cupcake-display" id="web2-cupcake"></div>

      <div class="balance">
        <span>Cupcake balance for <strong id="web2-who">—</strong>:</span>
        <span class="balance-count" id="web2-balance">0</span>
      </div>

      <div class="status" id="web2-status"></div>
    </div>



<script>
// ============================================================
// VendingMachine.js — the JavaScript class from the quickstart
// ============================================================
class VendingMachine {
  // state variables = internal memory of the vending machine
  cupcakeBalances = {};
  cupcakeDistributionTimes = {};

  // Vend a cupcake to the caller
  giveCupcakeTo(userId) {
    if (this.cupcakeDistributionTimes[userId] === undefined) {
      this.cupcakeBalances[userId] = 0;
      this.cupcakeDistributionTimes[userId] = 0;
    }

    // Rule 1: The vending machine will distribute a cupcake to anyone who hasn't recently received one.
    const fiveSeconds = 5000;
    const userCanReceiveCupcake = this.cupcakeDistributionTimes[userId] + fiveSeconds <= Date.now();
    if (!userCanReceiveCupcake) {
      console.error(
        'HTTP 429: Too Many Cupcakes (you must wait at least 5 seconds between cupcakes)',
      );
      return false;
    }

    this.cupcakeBalances[userId]++;
    this.cupcakeDistributionTimes[userId] = Date.now();
    console.log(`Enjoy your cupcake, ${userId}!`);
    return true;
  }

  getCupcakeBalanceFor(userId) {
    return this.cupcakeBalances[userId] || 0;
  }
}

// ============================================================
// VendingMachine.sol ABI (from the compiled Solidity contract)
// ============================================================
const VENDING_MACHINE_ABI = [
  {
    inputs: [{ internalType: "address", name: "userAddress", type: "address" }],
    name: "getCupcakeBalanceFor",
    outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
    stateMutability: "view",
    type: "function"
  },
  {
    inputs: [{ internalType: "address", name: "userAddress", type: "address" }],
    name: "giveCupcakeTo",
    outputs: [{ internalType: "bool", name: "", type: "bool" }],
    stateMutability: "nonpayable",
    type: "function"
  }
];

// ============================================================
// Helper: flash a cupcake emoji with fade-out
// ============================================================
function flashCupcake(elementId) {
  const el = document.getElementById(elementId);
  el.textContent = '\u{1F9C1}';
  el.style.opacity = 1;
  el.style.transition = 'none';
  requestAnimationFrame(() => {
    el.style.transition = 'opacity 4.5s ease-out';
    el.style.opacity = 0;
  });
}

function truncateAddress(text) {
  if (!text) return '—';
  if (text.length < 10) return text;
  return text.slice(0, 6) + '...' + text.slice(-4);
}

// ============================================================
// WEB2 Vending Machine
// ============================================================
(function initWeb2() {
  const vm = new VendingMachine();

  const nameInput    = document.getElementById('web2-name');
  const vendBtn      = document.getElementById('web2-vend');
  const refreshBtn   = document.getElementById('web2-refresh');
  const balanceEl    = document.getElementById('web2-balance');
  const whoEl        = document.getElementById('web2-who');
  const statusEl     = document.getElementById('web2-status');

  function refreshBalance() {
    const name = nameInput.value.trim() || 'no name';
    const bal = vm.getCupcakeBalanceFor(name);
    balanceEl.textContent = bal;
    whoEl.textContent = truncateAddress(name);
  }

  vendBtn.addEventListener('click', () => {
    const name = nameInput.value.trim() || 'no name';
    const got = vm.giveCupcakeTo(name);
    if (got) {
      statusEl.textContent = `Enjoy your cupcake, ${name}!`;
      statusEl.className = 'status success';
      flashCupcake('web2-cupcake');
      refreshBalance();
    } else {
      statusEl.textContent = 'Too many cupcakes! Wait at least 5 seconds.';
      statusEl.className = 'status';
    }
  });

  refreshBtn.addEventListener('click', refreshBalance);
})();

</script>

</body>
</html>

Now, let's decentralize our vending machine's business logic and data by porting the above JavaScript implementation into a Solidity smart contract.

Review the Solidity vending machine

Here is a Solidity implementation of the vending machine. Solidity is a language that compiles to EVM bytecode. This means that it is deployable to any Ethereum-compatible blockchain, including Ethereum mainnet, , and .

// SPDX-License-Identifier: MIT
// Specify the Solidity compiler version - this contract requires version 0.8.9 or higher
pragma solidity ^0.8.9;

// Define a smart contract named VendingMachine
// Unlike regular classes, once deployed, this contract's code cannot be modified
// This ensures that the vending machine's rules remain constant and trustworthy
contract VendingMachine {
   // State variables are permanently stored in blockchain storage
   // These mappings associate Ethereum addresses with unsigned integers
   // The 'private' keyword means these variables can only be accessed from within this contract
   mapping(address => uint) private _cupcakeBalances;     // Tracks how many cupcakes each address owns
   mapping(address => uint) private _cupcakeDistributionTimes;  // Tracks when each address last received a cupcake

   // Function to give a cupcake to a specified address
   // 'public' means this function can be called by anyone
   // 'returns (bool)' specifies that the function returns a boolean value
   function giveCupcakeTo(address userAddress) public returns (bool) {
       // Initialize first-time users
       // In Solidity, uninitialized values default to 0, so this check isn't strictly necessary
       // but is included to mirror the JavaScript implementation
       if (_cupcakeDistributionTimes[userAddress] == 0) {
           _cupcakeBalances[userAddress] = 0;
           _cupcakeDistributionTimes[userAddress] = 0;
       }

       // Calculate when the user is eligible for their next cupcake
       // 'seconds' is a built-in time unit in Solidity
       // 'block.timestamp' gives us the current time in seconds since Unix epoch
       uint fiveSecondsFromLastDistribution = _cupcakeDistributionTimes[userAddress] + 5 seconds;
       bool userCanReceiveCupcake = fiveSecondsFromLastDistribution <= block.timestamp;

       // If not enough time has passed, revert the transaction with an error message
       // 'require' cancels the transaction and returns the error message to the user when its condition is false
       require(userCanReceiveCupcake, "HTTP 429: Too Many Cupcakes (you must wait at least 5 seconds between cupcakes)");

       // Enough time has passed: give them a cupcake and update their last distribution time
       _cupcakeBalances[userAddress]++;
       _cupcakeDistributionTimes[userAddress] = block.timestamp;
       return true;
   }

   // Function to check how many cupcakes an address owns
   // 'public' means anyone can call this function
   // 'view' means this function only reads data and doesn't modify state
   // This makes it free to call (no gas cost) when called externally
   function getCupcakeBalanceFor(address userAddress) public view returns (uint) {
       return _cupcakeBalances[userAddress];
   }
}

Compile your smart contract with Remix

Smart contracts need to be compiled to bytecode to be stored and executed onchain by the EVM; we'll use Remix to do that.

Remix is a browser-based IDE for EVM development. There are other IDEs to choose from (Foundry, Hardhat), but Remix doesn't require any local environment setup, so we'll use it for this tutorial.

Let's first add our smart contract to Remix following these steps:

1. Load Remix

Open Remix in your browser.

2. Create a blank workspace in Remix

On the Home tab, click Create a new workspace, then Create blank.

3. Copy your vending machine contract

4. Paste your contract in Remix

In the File explorer, click Create, then New file. Name the file VendingMachine.sol, then paste your contract into it.

5. Compile your contract in Remix

Click Compile above the editor.

Note

Make sure that Remix's compiler version matches the one in your contract. You can find your contract's compiler version at the top of your contract's file. It looks like this:

pragma solidity ^0.8.9;

To change the compiler version, open the Compile panel from the left sidebar.

Deploy the smart contract to a local Ethereum chain

Once a smart contract gets compiled, it is deployable to a blockchain. The safest way to do this is to deploy it to a locally hosted chain, where you can test and debug your contract before deploying it to a public chain.

To deploy our VendingMachine smart contract locally, we will:

  1. Run Foundry's local Ethereum node in a terminal window
  2. Configure a wallet so we can interact with our smart contract after deployment (1)
  3. Deploy our smart contract to (1)'s node using Remix

Run a local chain

Here, we'll use Foundry's anvil to run a local Ethereum network and node.

curl -L https://foundry.paradigm.xyz | bash && anvil

                            _   _
                            (_) | |
      __ _   _ __   __   __  _  | |
     / _` | | '_ \  \ \ / / | | | |
    | (_| | | | | |  \ V /  | | | |
     \__,_| |_| |_|   \_/   |_| |_|

    1.10.1 (7c15a1dd0c 2026-11-26T19:03:37.081103000Z)
    https://github.com/foundry-rs/foundry

Available Accounts
==================

(0) 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000.000000000000000000 ETH)
(1) 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (10000.000000000000000000 ETH)
(2) 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC (10000.000000000000000000 ETH)
(3) 0x90F79bf6EB2c4f870365E785982E1f101E93b906 (10000.000000000000000000 ETH)
(4) 0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65 (10000.000000000000000000 ETH)
(5) 0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc (10000.000000000000000000 ETH)
(6) 0x976EA74026E726554dB657fA54763abd0C3a0aa9 (10000.000000000000000000 ETH)
(7) 0x14dC79964da2C08b23698B3D3cc7Ca32193d9955 (10000.000000000000000000 ETH)
(8) 0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f (10000.000000000000000000 ETH)
(9) 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 (10000.000000000000000000 ETH)

Private Keys
==================

(0) 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
(1) 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
(2) 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
(3) 0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6
(4) 0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a
(5) 0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba
(6) 0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e
(7) 0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356
(8) 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97
(9) 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6

Wallet
==================
Mnemonic:          test test test test test test test test test test test junk
Derivation path:   m/44'/60'/0'/0/


Chain ID
==================

31337

Base Fee
==================

1000000000

Gas Limit
==================

30000000

Genesis Timestamp
==================

1796123954

Genesis Number
==================

0

Listening on 127.0.0.1:8545

Configure Metamask

Next, open Metamask and create or import a wallet by following the displayed instructions.

By default, Metamask will connect to Ethereum's mainnet. To connect to our local "testnet," enable test networks for Metamask by clicking Show/hide test networks.

Next, click Metamask's network selector dropdown and click the Add Network button. Click Add a network manually and then provide the following information:

  • Network Name: localhost
  • New RPC URL: http://127.0.0.1:8545
  • Chain ID: 31337
  • Currency Symbol: ETH

Your wallet won't have a balance on your local testnet's node, but you can import one of the test accounts into Metamask to access to 10,000 testnet ETH. Copy the private key of one of the test accounts (it works with or without the 0x prefix, so e.g., 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 or ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80) and import it into Metamask. Metamask will ask you if you want to connect this new account to Remix, to which you should answer "yes":

Connect Metamask to Localhost 8545

Never share your private keys

Your Ethereum Mainnet wallet's private key is the password to all of your tokens. Never share it with anyone; avoid copying it to your clipboard.

Note that in the context of this quickstart, "account" refers to an EOA (externally owned account), and its associated private key5.

You should see a balance of 10,000 ETH. Keep your private key handy; we'll use it again shortly.

As we interact with our cupcake vending machine, we'll use Metamask's network selector dropdown to choose which network our cupcake transactions get sent to. We'll leave the network set to Localhost 8545 for now.

Deploy the smart contract to your local chain

  1. In Remix, click Deploy in the left sidebar.
  2. In the Environment dropdown, select Custom - External Http Provider.
  3. When Remix asks for the RPC endpoint, keep the default http://127.0.0.1:8545, the address anvil listens on, and confirm.
  4. Click Deploy.
  5. Under Deployed Contracts, copy the contract address shown in the VendingMachine entry.

Then paste your contract address below and click Get cupcake!. A prompt should ask you to sign a transaction that gives you a cupcake.

Free Cupcakes

web3-localhost

Cupcake balance:0 (no name)

What's going on, here?

Our first VendingMachine is labeled "Web2" because it demonstrates traditional client-server web application architecture: the back-end lives in a centralized network of servers.

Architecture diagram

The "Web3" architecture is similar to the "Web2" architecture, with one key difference: with the "Web3" version, business logic and data are hosted by decentralized network of nodes

Let's take a closer look at the differences between our VendingMachine implementations:

WEB2
(the first one)
WEB3-LOCALHOST
(the latest one)
WEB3-ARB-SEPOLIA
(the next one)
WEB3-ARB-MAINNET
(the final one)
Data (cupcakes)Stored only in your browser. (Usually, stored by centralized infrastructure.)Stored on your device in an emulated Ethereum network (via smart contract).Stored on Arbitrum's decentralized test network (via smart contract).Stored on Arbitrum's decentralized mainnet network (via smart contract).
Logic (vending)Served from Offchain's servers. Executed by your browser.Stored and executed by your locally emulated Ethereum network (via smart contract).Stored and executed by Arbitrum's decentralized test network (via smart contract).Stored and executed by Arbitrum's decentralized mainnet network (via smart contract).
Presentation (UI)Served from Offchain's servers. Rendered and executed by your browser.← same← same← same
MoneyDevs pay centralized service providers for servers, in fiat currency.Devs pay for frontend hosting only. Transactions pay gas in anvil's test ETH, which has no value.Devs pay gas to deploy, and users pay gas for each transaction, in testnet ETH. The fees go to the chain's poster and network fee account.← same, but in mainnet ETH.

So far, we've deployed our "Web3" app to an emulated blockchain (Anvil), which is a normal step in EVM development.

Next, we'll deploy our smart contract to a network of real nodes: Arbitrum's Sepolia testnet.

Deploy the smart contract to the Arbitrum Sepolia testnet

Your local deploy was free because anvil's test ETH has no value. Now we'll deploy our contract to Arbitrum's Sepolia testnet. Sepolia is powered by a network of nodes ran across the world by various participants, we'll need to compensate them with a small transaction fee in order to deploy our smart contract.

To be able to pay the transaction fee, we will:

  • Use our MetaMask crypto wallet
  • Obtain some Arbitrum Sepolia testnet's token called ETH.

Click Metamask's Network selector dropdown, and then click the Add Network button. Click Add a network manually and then provide the following information:

  • Network Name: Arbitrum Sepolia
  • New RPC URL: https://sepolia-rollup.arbitrum.io/rpc
  • Chain ID: 421614
  • Currency Symbol: ETH

As we interact with the cupcake vending machine, we'll use Metamask's network selector dropdown to determine which network our cupcake transactions are sent to.

Next, add some ETH to your MetaMask account on Arbitrum Sepolia. Remix has no wallet of its own: for this deploy, Remix connects through MetaMask and deploys from your MetaMask account.

Use your own account, not the anvil test account

Anvil's test private keys are public. If you send ETH to an anvil test account on a public network, anyone can take it. Fund and deploy from an account you created in MetaMask.

  1. Copy your account address from MetaMask.
  2. Request Arbitrum Sepolia ETH for that address from a faucet in the faucet list.
  3. If the faucet gives you Sepolia ETH on Ethereum instead, move it to Arbitrum Sepolia with the Arbitrum bridge.

Once your account holds some ETH, deploy your contract to Arbitrum Sepolia:

  1. In MetaMask, select the Arbitrum Sepolia network and your funded account.
  2. In Remix, click Deploy in the left sidebar.
  3. In the Environment dropdown, select Browser Extension, then approve the connection in MetaMask.
  4. Click Deploy, then confirm the transaction in MetaMask.
  5. Under Deployed Contracts, copy the contract address shown in the VendingMachine entry.

MetaMask signs the deploy with your account and sends it to the Arbitrum Sepolia RPC URL you added.

Congratulations! You've just deployed business logic and data to Arbitrum Sepolia. This logic and data will be hashed and submitted within a transaction to Ethereum's parent chian Sepolia network, and then it will be mirrored across all nodes in the Sepolia network6.

To view your smart contract in a blockchain explorer, visit https://sepolia.arbiscan.io/address/0x...B3, but replace the 0x...B3 part of the URL with the full address of your deployed smart contract.

Select Arbitrum Sepolia from Metamask's dropdown, paste your contract address into the VendingMachine below, and click Get cupcake!. You should be prompted to sign a transaction that gives you a cupcake.

Free Cupcakes

web3-arb-sepolia

Cupcake balance:0 (no name)

The final step is deploying our Cupcake machine to a production network, such as Ethereum, Arbitrum One, or Arbitrum Nitro. The good news is: deploying a smart contract in production is exactly the same as for Sepolia Testnet. The harder news: it will cost real money, this time. If you deploy on Ethereum, the fees can be significant and the transaction confirmation time 12 seconds on average. Arbitrum, a child chain, reduces these costs about 10X and a confirmation time in the same order while maintaining a similar level of security and decentralization. For an in-depth look at how fees are calculated and estimated, see How to estimate gas.

Summary

In this quickstart, we:

  • Identified two business rules: 1) fair and permissionless cupcake distribution 2) immutable business logic and data.
  • Identified a challenge: These rules are difficult to follow in a centralized application.
  • Identified a solution: Using Arbitrum, we can decentralize business logic and data.
  • Converted a vending machine's Javascript business logic into a Solidity smart contract.
  • Deployed our smart contract to a local development network, and then Arbitrum's Sepolia testnet.

If you have any questions or feedback, reach out to us on Discord and/or click the Request an update button at the top of this page—we're listening!

Learning resources

For a list of learning resources, repositories, and useful information about Solidity, see the Solidity references page.

Footnotes

  1. The vending machine example was inspired by Ethereum.org's "Introduction to Smart Contracts", which was inspired by Nick Szabo's "From vending machines to smart contracts". ↩

  2. Although application front-ends are usually hosted by centralized services, smart contracts allow the underlying logic and data to be partially or fully decentralized. These smart contracts are hosted and executed by Ethereum's public, decentralized network of nodes. Arbitrum has its own network of nodes that use advanced cryptography techniques to "batch process" Ethereum transactions and then submit them to the Ethereum parent chain, which significantly reduces the cost of using Ethereum. All without requiring developers to compromise on security or decentralization. ↩

  3. There are multiple types of Ethereum nodes. The ones that earn ETH for processing and validating transactions are called validators. See Nodes and Networks for a beginner-friendly introduction to Ethereum's node types. ↩

  4. When our VendingMachine contract is deployed to Ethereum, it'll be hosted by Ethereum's decentralized network of nodes. Generally speaking, we won't be able to modify the contract's code after it's deployed. ↩

  5. To learn more about how Ethereum wallets work, see Ethereum.org's introduction to Ethereum wallets. ↩

  6. Visit the Gentle Introduction to Arbitrum for a beginner-friendly introduction to Arbitrum's Rollup protocol. ↩

How is this guide?

On this page