> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ralphstudio.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploying Contracts

> Deploy a Ralph smart contract using the Ralph Studio IDE.

Ralph Studio includes a browser-based IDE for writing, compiling, and deploying Ralph contracts directly to Alephium mainnet or testnet. No local toolchain required.

## Open the IDE

Navigate to **Ralph Studio** → [IDE](https://ide.ralphstudio.xyz) in the dashboard sidebar. You will see a split editor, Ralph source on the left, compiler output and deployment panel on the right.

## Write your contract

Paste or write your Ralph contract in the editor. Here is a minimal example to deploy:

```ralph theme={null}
import "std/fungible_token_interface"

Contract TokenFaucet(
  symbol: ByteVec,
  name: ByteVec,
  decimals: U256,
  mut balance: U256
) implements IFungibleToken {

  event Withdraw(to: Address, amount: U256)

  enum ErrorCodes {
    InvalidWithdrawAmount = 0
  }

  pub fn getSymbol() -> ByteVec {
    return symbol
  }

  pub fn getName() -> ByteVec {
    return name
  }

  pub fn getDecimals() -> U256 {
    return decimals
  }

  pub fn getTotalSupply() -> U256 {
    return balance
  }

  @using(assetsInContract = true, updateFields = true, checkExternalCaller = false)
  pub fn withdraw(to: Address, amount: U256) -> () {
    assert!(amount <= 2 alph, ErrorCodes.InvalidWithdrawAmount)
    balance = balance - amount
    transferTokenFromSelf!(to, selfTokenId!(), amount)
    transferTokenFromSelf!(to, ALPH, dustAmount!())
    emit Withdraw(to, amount)
  }
}
```

## Compile

Click **Compile** in the IDE toolbar. The compiler output panel shows:

* **Bytecode**: the compiled contract ready for deployment
* **ABI**: the function signatures and field types
* **Warnings**: unused variables, missing annotations, and other non-fatal issues
* **Errors**: problems that must be fixed before deployment

Fix all errors before proceeding. Warnings do not block deployment but are worth reviewing.

## Set initial fields

Before deploying you set the initial values for all contract fields. The IDE shows a form generated from the ABI:

| Field      | Type    | Example value                           |
| ---------- | ------- | --------------------------------------- |
| `symbol`   | ByteVec | `546f6b656e` (hex for "Token")          |
| `name`     | ByteVec | `4d7920546f6b656e` (hex for "My Token") |
| `decimals` | U256    | `18`                                    |
| `balance`  | U256    | `1000000000000000000000`                |

Immutable fields cannot be changed after deployment. Double-check them before signing.

## Connect your wallet

Click **Connect Wallet** and approve the connection in your Alephium extension wallet. The IDE supports:

* Alephium Extension Wallet (Chrome/Firefox)

The connected wallet pays the deployment transaction fee and signs the transaction.

## Deploy

Click **Deploy**. The IDE builds a deployment transaction and sends it to your connected wallet for signing. After signing:

1. The transaction is broadcast to the network
2. The IDE polls for confirmatior, typically 16–32 seconds
3. Once confirmed the contract address appears in the deployment panel

Save the contract address. It is permanent the same address is used for all future interactions.

## Verify deployment

Confirm the contract is live by querying its state:

```bash theme={null}
curl "https://rpc.ralphstudio.xyz/{your-slug}/contracts/{contract-address}/state" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

```json theme={null}
{
  "address": "27Gsc5...",
  "bytecode": "0101...",
  "immFields": [...],
  "mutFields": [...],
  "asset": {
    "attoAlphAmount": "1000000000000000000"
  }
}
```

## Deploying to testnet

Switch the network selector in the IDE from **Mainnet** to **Testnet** before deploying. Testnet ALPH is free, use the faucet in your Alephium wallet to get test funds.

Always deploy and test on testnet before mainnet. Contract addresses differ between networks.

## Next steps

<CardGroup cols={2}>
  <Card title="Interacting with contracts" icon="plug" href="/smart-contracts/interacting">
    Call functions on your deployed contract
  </Card>

  <Card title="Contract events" icon="bolt" href="/smart-contracts/events">
    Query events emitted by your contract
  </Card>
</CardGroup>
