Sepolia
Sepolia testnet chain definition and usage for development and testing
Loading...
Sepolia testnet chain definition and usage for development and testing
Sepolia is an Ethereum testnet used for development and testing. viem-go does not ship a built-in definitions.Sepolia; define it with DefineChain and the same chain.Chain struct, then pass a pointer to your clients.
import ( "github.com/ChefBingbong/viem-go/client" "github.com/ChefBingbong/viem-go/client/transport" "github.com/ChefBingbong/viem-go/chain")Define the Sepolia chain once (e.g. in an init or package var) and pass a pointer when creating clients.
import ( "log"
"github.com/ChefBingbong/viem-go/client" "github.com/ChefBingbong/viem-go/client/transport" "github.com/ChefBingbong/viem-go/chain")
var Sepolia = chain.DefineChain(chain.Chain{ ID: 11155111, Name: "Sepolia", NativeCurrency: chain.ChainNativeCurrency{ Name: "Sepolia Ether", Symbol: "ETH", Decimals: 18, }, BlockTime: int64Ptr(12), Testnet: true, RpcUrls: map[string]chain.ChainRpcUrls{ "default": { HTTP: []string{"https://rpc.sepolia.org"}, }, }, BlockExplorers: map[string]chain.ChainBlockExplorer{ "default": { Name: "Etherscan", URL: "https://sepolia.etherscan.io", ApiURL: "https://api-sepolia.etherscan.io/api", }, },})
func int64Ptr(n int64) *int64 { return &n }
func main() { publicClient, err := client.CreatePublicClient(client.PublicClientConfig{ Chain: &Sepolia, Transport: transport.HTTP("https://rpc.sepolia.org"), }) if err != nil { log.Fatal(err) } defer publicClient.Close()}| Property | Value |
|---|---|
| ID | 11155111 |
| Name | "Sepolia" |
| Native currency | Sepolia Ether (ETH), 18 decimals |
| Testnet | true |
| Default RPC | https://rpc.sepolia.org (or your own endpoint) |
| Block explorer | sepolia.etherscan.io |
Get testnet ETH from public faucets, for example:
definitions.Sepolia in viem-go. Use chain.DefineChain(chain.Chain{...}) as above and keep the result (e.g. package-level var); pass &Sepolia to clients.Sepolia.DefaultRpcUrl() if your definition's RpcUrls["default"].HTTP[0] is set, or pass any Sepolia RPC URL to transport.HTTP(...).Chain type and DefineChain options