Avalanche
Prêt à utiliser cela en production ?
Le niveau gratuit couvre les projets personnels. Le paiement à l'usage évolue sans carte bancaire.
Avalanche
Le niveau gratuit couvre les projets personnels. Le paiement à l'usage évolue sans carte bancaire.
go-ethereum (geth) is the official Go implementation of the EVM and the most complete, up-to-date library for building on the Avalanche C-Chain in Go. Because the C-Chain is EVM-equivalent at chain ID 43114, geth's ethclient talks to https://avalanche.therpc.io/YOUR_API_KEY with no Avalanche-specific changes, and AVAX is simply the native value moved by transactions. Install it with go get github.com/ethereum/go-ethereum. It is maintained by the Ethereum Foundation, so it tracks protocol upgrades closely.
go-ethereum is the official Go client, maintained by the Ethereum Foundation, and gives Go developers the most complete and current EVM implementation available — a solid foundation for backends, indexers, and bots running against the Avalanche C-Chain.
Connect by calling ethclient.Dial("https://avalanche.therpc.io/YOUR_API_KEY"), which returns a client ready to query the C-Chain. Wrapping that client in your own struct — as the example below does — keeps connection setup in one place and makes the code easy to mock and unit-test without hitting the live Avalanche endpoint.
For type-safe contract access on the C-Chain, run abigen over a Solidity ABI to generate Go bindings — strongly typed methods for a Trader Joe router, an Aave pool, or your own contract. Under the hood these wrap bind.BoundContract, which couples the ABI to the client and exposes Call for read-only view methods and Transact for writes that submit a signed transaction and spend AVAX gas.
SubscribeNewHead opens a push subscription, which requires a WebSocket connection — the HTTP endpoint cannot stream events, so for live block notifications dial the WebSocket variant of the C-Chain endpoint instead. Run the subscription in a goroutine and use select to handle both incoming headers and the subscription's error channel, so a dropped connection is caught and can be re-dialed. With Avalanche finalizing blocks in roughly 1–2 seconds, new headers arrive quickly and steadily.
AVAX amounts on the C-Chain are denominated in wei (18 decimals), and those values overflow and lose precision in float64. Always do the math in big.Int for exact integer wei and big.Float only when converting to a display value — the helpers below convert between wei and whole AVAX without rounding errors.