Arbitrum dApp Development
Stack
| Layer | Tool | Notes |
|---|
| Smart contracts (Rust) | INLINECODE0 v0.10+ | Compiled to WASM, runs on Stylus VM |
| Smart contracts (Solidity) |
Solidity 0.8.x + Foundry | Standard EVM path on Arbitrum |
| Local node |
nitro-devnode | Docker-based local Arbitrum chain |
| Contract CLI |
cargo-stylus | Check, deploy, export-abi for Stylus |
| Contract toolchain | Foundry (
forge,
cast,
anvil) | Build, test, deploy, interact for Solidity |
| Frontend | React / Next.js + viem + wagmi | viem for all chain interaction |
| Package manager | pnpm | Workspace-friendly, fast |
Decision Flow
When starting a new contract:
- 1. Need max performance / lower gas? → Stylus Rust. See
references/stylus-rust-contracts.md. - Need broad tooling compatibility / rapid prototyping? → Solidity. See
references/solidity-contracts.md. - Hybrid? → Use both. Stylus and Solidity contracts are fully interoperable on Arbitrum.
Project Scaffolding
Monorepo layout (recommended)
CODEBLOCK0
Bootstrap steps
CODEBLOCK1
Core Workflow
Stylus Rust
CODEBLOCK2
Solidity (Foundry)
CODEBLOCK3
Note: The nitro-devnode ships with a pre-funded deployer account. See references/local-devnode.md for the default private key and address. For testnet/mainnet, use your own key via environment variables — never hardcode secrets.
Frontend (viem + wagmi)
CODEBLOCK4
See references/frontend-integration.md for full patterns with wagmi hooks, wallet connection, and write transactions.
Principles
- - Always use viem for chain interaction.
- Test locally first against nitro-devnode before deploying to testnet.
- Export ABIs from both Stylus (
cargo stylus export-abi) and Solidity (forge inspect) and keep them in a shared location the frontend can import. - Use environment variables for RPC URLs, contract addresses, and private keys. Never hardcode secrets.
- Stylus contracts are EVM-compatible — they share the same address space, storage model, and ABI encoding as Solidity contracts. Cross-contract calls work seamlessly.
References
Load these as needed for deeper guidance:
- -
references/stylus-rust-contracts.md — Stylus SDK patterns, storage, macros, entrypoints - INLINECODE13 — Solidity on Arbitrum specifics and Foundry workflow
- INLINECODE14 — React + viem + wagmi patterns
- INLINECODE15 — Nitro devnode setup, accounts, and debugging
- INLINECODE16 — Deploying to testnet and mainnet
- INLINECODE17 — Testing strategies for both Stylus and Solidity
Arbitrum dApp 开发
技术栈
| 层级 | 工具 | 说明 |
|---|
| 智能合约 (Rust) | stylus-sdk v0.10+ | 编译为 WASM,在 Stylus VM 上运行 |
| 智能合约 (Solidity) |
Solidity 0.8.x + Foundry | Arbitrum 上的标准 EVM 路径 |
| 本地节点 | nitro-devnode | 基于 Docker 的本地 Arbitrum 链 |
| 合约 CLI | cargo-stylus | 检查、部署、导出 Stylus 的 ABI |
| 合约工具链 | Foundry (forge, cast, anvil) | 构建、测试、部署、交互 Solidity 合约 |
| 前端 | React / Next.js + viem + wagmi | 使用 viem 进行所有链交互 |
| 包管理器 | pnpm | 工作区友好,速度快 |
决策流程
在开始新合约时:
- 1. 需要最高性能 / 更低 Gas? → Stylus Rust。参见 references/stylus-rust-contracts.md。
- 需要广泛的工具兼容性 / 快速原型开发? → Solidity。参见 references/solidity-contracts.md。
- 混合方案? → 两者兼用。Stylus 和 Solidity 合约在 Arbitrum 上完全可互操作。
项目脚手架
单仓库布局(推荐)
my-arbitrum-dapp/
├── apps/
│ ├── frontend/ # React / Next.js 应用
│ ├── contracts-stylus/ # Rust Stylus 合约
│ ├── contracts-solidity/ # Foundry Solidity 合约
│ └── nitro-devnode/ # 本地开发链(git 子模块)
├── pnpm-workspace.yaml
└── package.json
初始化步骤
bash
1. 创建工作区
mkdir my-arbitrum-dapp && cd my-arbitrum-dapp
pnpm init
printf packages:\n - apps/*\n > pnpm-workspace.yaml
2. 本地开发节点
git clone https://github.com/OffchainLabs/nitro-devnode.git apps/nitro-devnode
cd apps/nitro-devnode && ./run-dev-node.sh && cd ../..
3a. Stylus 合约
cargo stylus new apps/contracts-stylus
3b. Solidity 合约
cd apps && forge init contracts-solidity && cd ..
4. 前端
pnpm create next-app apps/frontend --typescript
cd apps/frontend
pnpm add viem wagmi @tanstack/react-query
核心工作流
Stylus Rust
bash
验证
cargo stylus check --endpoint http://localhost:8547
部署(使用 nitro-devnode 预充值的部署者账户)
cargo stylus deploy \
--endpoint http://localhost:8547 \
--private-key $PRIVATE_KEY
导出 ABI 供前端使用
cargo stylus export-abi
Solidity (Foundry)
bash
构建
forge build
测试
forge test
本地部署(使用 nitro-devnode 预充值的部署者账户)
forge script script/Deploy.s.sol --rpc-url http://localhost:8547 --broadcast \
--private-key $PRIVATE_KEY
注意: nitro-devnode 附带一个预充值的部署者账户。默认私钥和地址请参见 references/local-devnode.md。对于测试网/主网,请通过环境变量使用您自己的密钥——切勿硬编码机密信息。
前端 (viem + wagmi)
typescript
import { createPublicClient, http } from viem;
import { arbitrumSepolia } from viem/chains;
const client = createPublicClient({
chain: arbitrumSepolia,
transport: http(),
});
// 从合约读取
const result = await client.readContract({
address: 0x...,
abi: contractAbi,
functionName: myFunction,
});
完整的 wagmi 钩子、钱包连接和写入交易模式请参见 references/frontend-integration.md。
原则
- - 始终使用 viem 进行链交互。
- 先在本地测试,在部署到测试网之前使用 nitro-devnode。
- 导出 ABI,包括 Stylus(cargo stylus export-abi)和 Solidity(forge inspect)的 ABI,并将其放在前端可以导入的共享位置。
- 使用环境变量 存储 RPC URL、合约地址和私钥。切勿硬编码机密信息。
- Stylus 合约与 EVM 兼容——它们与 Solidity 合约共享相同的地址空间、存储模型和 ABI 编码。跨合约调用无缝工作。
参考资料
根据需要加载以下内容以获取更深入的指导:
- - references/stylus-rust-contracts.md — Stylus SDK 模式、存储、宏、入口点
- references/solidity-contracts.md — Arbitrum 上的 Solidity 特性和 Foundry 工作流
- references/frontend-integration.md — React + viem + wagmi 模式
- references/local-devnode.md — Nitro 开发节点设置、账户和调试
- references/deployment.md — 部署到测试网和主网
- references/testing.md — Stylus 和 Solidity 的测试策略