toCoinType
Converts a chain ID to an ENSIP-9 compliant coin type
Loading...
Converts a chain ID to an ENSIP-9 compliant coin type
Converts a chain ID to an ENSIP-9 compliant coin type.
import "github.com/ChefBingbong/viem-go/utils/ens"import "github.com/ChefBingbong/viem-go/utils/ens"
// Ethereum mainnet (chainId 1) uses SLIP-44 coin type 60coinType, err := ens.ToCoinType(1)if err != nil { log.Fatal(err)}// 60
// Optimism (chainId 10)coinType, _ = ens.ToCoinType(10)// 2147483658
// Polygon (chainId 137)coinType, _ = ens.ToCoinType(137)// 2147483785
// Panic on errorcoinType = ens.MustToCoinType(1)// 60(uint64, error) for ToCoinType, uint64 for MustToCoinTypeThe coin type for the chain ID.
intThe chain ID to convert. Must be >= 0 and < 0x80000000.
coinType, _ := ens.ToCoinType(1)// 60
coinType, _ = ens.ToCoinType(10)// 214748365860 (ETH's SLIP-44 coin type)0x80000000 | chainIdConverts chain ID to coin type:
coinType, _ := ens.ToCoinType(1)
Converts chain ID to coin type or panics:
coinType := ens.MustToCoinType(1)
0x80000000 | chainId