Base
هل أنت مستعد لاستدعاء هذا في الإنتاج؟
الخطة المجانية تغطي المشاريع الشخصية. الدفع حسب الاستخدام يتوسع دون بطاقة.
Base
الخطة المجانية تغطي المشاريع الشخصية. الدفع حسب الاستخدام يتوسع دون بطاقة.
web3.swift is the primary Swift library for building on Base, targeting iOS 13+ and macOS 10.15+ with a native, type-safe API. Since Base is an EVM-equivalent OP Stack rollup with ETH gas, the same calls reach it at https://base.therpc.io/YOUR_API_KEY (chain ID 8453) that you'd use on any Ethereum-style chain — a good fit for the consumer and social apps the Base ecosystem is known for. Add it through Swift Package Manager using the repository at https://github.com/argentlabs/web3.swift.
web3.swift targets iOS 13+ and macOS 10.15+, so it covers modern Apple platforms for your Base app. Add it with Swift Package Manager, pointing at the argentlabs/web3.swift repository.
Create a client with Web3(rpcURL: "https://base.therpc.io/YOUR_API_KEY"), pointing it at your Base endpoint. Every network call is async throws, so invoke it from an async context — inside a Task { } or another async function — and use try await. This pairs naturally with SwiftUI's .task modifier for fetching Base data when a view appears.
For SwiftUI, hold your Base state in an ObservableObject view model and expose it to the view with @StateObject, marking the balance @Published so the UI updates automatically when it changes. Trigger the async web3.swift calls from inside a Task { } — launched from a Button action or a .task modifier — so the network request runs off the main thread while the view stays responsive.
To call a contract on Base, load its ABI JSON and create a contract handle through web3.eth.Contract(json:address:), then invoke methods on it with try await. You can copy the ABI and address of any verified Base contract from https://basescan.org to wire it into your app.
Define a typed EthereumError enum so your app can tell an invalid-address mistake apart from a Base network failure and react to each differently in the UI. Validate the address format — at minimum the 0x prefix — before making any network call, which avoids wasting a round-trip to the Base node on input that could never succeed.