wallet-adapter-eth

command module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 7 Imported by: 0

README

wallet-adapter-eth

Module path: github.com/godaddy-x/wallet-adapter-eth

Ethereum and EVM-compatible chain wallet-adapter subclass implementation, providing a unified ChainAdapter for BSC, Polygon, Arbitrum, and others. Supports native coin and ERC20 transaction building, EIP-155 signing, and raw transaction broadcast, compatible with external MPC signing services; configuration is passed via LoadAssetsConfig callback, supporting multiple formats defined by wallet-adapter/config (JSON/INI, etc.).

Overview

  • Base framework: wallet-adapter ChainAdapter (SymbolInfo, AssetsConfig, TransactionDecoder, BlockScanner, AddressDecoder).
  • Implementation highlights: Uses github.com/godaddy-x/wallet-adapter types.RawTransaction, wallet.WalletDAI, etc.; implements decoder.TransactionDecoder, decoder.AddressDecoder, decoder.SmartContractDecoder; EVM chain config (WalletConfig) in internal/config, loaded via wallet-adapter/config Configer interface, supporting JSON/INI and other formats.

Project structure (by package)

wallet-adapter-eth/
├── go.mod
├── go.sum
├── main.go              # entry point (one-line startup from JSON config)
├── build_release.bat, build_release.sh
├── .github/workflows/release.yml   # tag → Release + SHA256SUMS
├── README.md
├── LICENSE
├── resource/
│   └── config.json      # sample config (JSON format)
├── eth/                 # public package: adapter and one-line startup
│   ├── doc.go
│   ├── adapter.go       # EthAdapter, NewEthAdapter
│   └── run.go           # NewAdapter(jsonContent, symbol, fullName, decimals)
└── internal/            # internal packages (module use only)
    ├── config/          # WalletConfig (EVM), BuildConfigFromConfiger (uses wallet-adapter/config Configer)
    ├── decoder/         # AddressDecoder, TransactionDecoder, SmartContractDecoder (github.com/godaddy-x/wallet-adapter/decoder)
    │   ├── address.go
    │   ├── transaction.go
    │   └── contract.go
    ├── manager/         # WalletManager (RPC, nonce, gas, balance, broadcast)
    │   └── manager.go
    ├── models/          # TxFeeInfo, AddrBalance, CallMsg
    │   └── models.go
    ├── rpc/             # JSON-RPC client (Dial, Call, broadcast)
    │   └── client.go
    └── util/            # StringToBigInt, BigIntToDecimal, Append0x
        ├── addr.go
        └── decimal.go

Dependencies

Official releases

Prebuilt binaries are available from GitHub Releases. Pushing a v* tag triggers .github/workflows/release.yml cross-compilation and release:

Artifact Platform
wallet-adapter-eth-linux-amd64 Linux x86_64
wallet-adapter-eth-linux-arm64 Linux ARM64
wallet-adapter-eth-darwin-amd64 macOS Intel (x86_64)
wallet-adapter-eth-darwin-arm64 macOS Apple Silicon (ARM64)
wallet-adapter-eth-windows-amd64.exe Windows x86_64
SHA256SUMS SHA-256 checksums for the above binaries

Verify before deployment:

# Linux / macOS — run in download directory (ignore missing files when downloading single platform)
sha256sum -c --ignore-missing SHA256SUMS
# Windows — compare with wallet-adapter-eth-windows-amd64.exe line in SHA256SUMS
Get-FileHash .\wallet-adapter-eth-windows-amd64.exe -Algorithm SHA256

Maintainer release:

git tag v1.0.5
git push origin v1.0.5

Cross-compile (static link CGO_ENABLED=0, output in output/):

build_release.bat          REM Windows
chmod +x build_release.sh && ./build_release.sh   # Linux / macOS

Usage

1. One-line startup (create and register adapter from JSON content)
import (
    "github.com/godaddy-x/wallet-adapter-eth/eth"
)

// jsonContent is a JSON config string, parsed via wallet-adapter/config MapConfig
// Supported fields: serverAPI, broadcastAPI, dataDir, chainID, fixGasLimit, fixGasPrice, offsetsGasPrice, gasPriceUpliftPercent, etc.
adapter, err := eth.NewAdapter(jsonContent, "ETH", "Ethereum", 18)
if err != nil {
    return err
}
// adapter is *eth.EthAdapter, registered to chain, with RPC client set; fetches chainID from node if ChainID is 0
2. Set RPC and get decoders
import (
    "github.com/godaddy-x/wallet-adapter/chain"
    "github.com/godaddy-x/wallet-adapter-eth/eth"
    "github.com/godaddy-x/wallet-adapter-eth/internal/rpc"
)

// Connect to node (read/write can be separated: broadcast uses BroadcastURL)
client, err := rpc.Dial("https://eth-mainnet.g.alchemy.com/v2/xxx", "https://eth-mainnet.g.alchemy.com/v2/yyy")
if err != nil {
    return err
}
defer client.Close()

a, _ := chain.GetAdapter("ETH")
if e, ok := a.(*eth.EthAdapter); ok {
    e.SetClient(client)
    _, _ = e.SetNetworkChainID() // fetch chainId from node and write to Config
}

decoder, _ := chain.GetTransactionDecoder("ETH")
addressDecoder, _ := chain.GetAddressDecoder("ETH")
3. Build and broadcast transactions (with flow + WalletDAI)
import (
    "github.com/godaddy-x/wallet-adapter/chain"
    "github.com/godaddy-x/wallet-adapter/flow"
)

// wrapper must implement wallet.WalletDAI (SignPendingTxData, GetAddressList, etc.)
pending, err := flow.BuildTransaction(decoder, wrapper, rawTx)
// ... MPC signing fills pending.SignerList ...
tx, err := flow.SendTransaction(decoder, wrapper, pending)
4. Multi-chain (BSC, Polygon, Arbitrum)

To support multiple chains with the same code, use NewEthAdapter(symbol, fullName, decimals) then LoadAssetsConfig(c) to initialize config and RPC (c is github.com/godaddy-x/wallet-adapter/config.Configer or map[string]string):

import (
    "github.com/godaddy-x/wallet-adapter/chain"
    "github.com/godaddy-x/wallet-adapter/config"
    "github.com/godaddy-x/wallet-adapter-eth/eth"
)

func registerEvmChains() {
    chains := []struct{ symbol, fullName, api string }{
        {"ETH", "Ethereum", "https://eth.llamarpc.com"},
        {"BSC", "BNB Smart Chain", "https://bsc-dataseed.binance.org"},
        {"MATIC", "Polygon", "https://polygon-rpc.com"},
        {"ARB", "Arbitrum One", "https://arb1.arbitrum.io/rpc"},
    }
    for _, c := range chains {
        adapter := eth.NewEthAdapter(c.symbol, c.fullName, 18)
        chain.RegAdapter(c.symbol, adapter)
        kv := map[string]string{"serverAPI": c.api, "broadcastAPI": c.api}
        _ = adapter.LoadAssetsConfig(config.MapConfig(kv))
    }
}

Current capabilities

Capability Description
Native ETH transfer CreateRawTransaction / SubmitRawTransaction / VerifyRawTransaction
ERC20 transfer CreateRawTransaction (transfer tx when IsContract) / SubmitRawTransaction / VerifyRawTransaction
Fee rate GetRawTransactionFeeRate, EstimateRawTransactionFee
Summary CreateSummaryRawTransactionWithError (native coin only)
Address AddressDecode / AddressEncode / AddressVerify, PublicKeyToAddress (EVM 0x+20 bytes)
MPC signing Supports 64-byte R|S to 65-byte R|S|V, EIP-155 chainId
BlockScanner Implemented (EthBlockScanner); see internal/scanner

Local testing (main + JSON)

Root main.go embeds a JSON example and blocks; optional -addr tests balance and nonce for a given address:

# Run directly (uses embedded JSON config in code)
go run .

# With address: prints balance and nonce
go run . -addr 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045

JSON config example in resource/config.json; configure serverAPI, broadcastAPI, dataDir, etc.

Documentation

Location Description
This README Project overview, structure, dependencies, usage, capability table
eth/doc.go Public eth package docs and usage examples
internal/config EVM WalletConfig, BuildConfigFromConfiger (depends on github.com/godaddy-x/wallet-adapter/config)
internal/manager WalletManager, LoadAssetsConfig, RPC/balance/broadcast
internal/decoder AddressDecoder, TransactionDecoder, SmartContractDecoder (EVM/ERC20 token balance and metadata)
internal/rpc, models, util JSON-RPC client, internal models, decimal and address utilities
docs/PENDING_SIGN_VERIFY.md Pending sign verification and cross-check
internal/scanner/flow.md Block scanner flow documentation

License

MIT

Documentation

Overview

main is the test entry point for this module (github.com/godaddy-x/wallet-adapter-eth): creates and registers an adapter from embedded JSON config via eth.NewAdapter, prints chain info and optional address balance/nonce, then blocks. Use -addr to specify a test address.

Directories

Path Synopsis
Package eth implements an Ethereum and EVM-compatible chain adapter based on [wallet-adapter](https://github.com/godaddy-x/wallet-adapter).
Package eth implements an Ethereum and EVM-compatible chain adapter based on [wallet-adapter](https://github.com/godaddy-x/wallet-adapter).
internal
config
Package config provides chain configuration used by this adapter (EVM: RPC, Gas, Nonce, etc.), depending on github.com/godaddy-x/wallet-adapter/config Configer interface.
Package config provides chain configuration used by this adapter (EVM: RPC, Gas, Nonce, etc.), depending on github.com/godaddy-x/wallet-adapter/config Configer interface.
decoder
Package decoder implements github.com/godaddy-x/wallet-adapter decoder types: AddressDecoder (EVM addresses) and TransactionDecoder (tx build/verify/broadcast).
Package decoder implements github.com/godaddy-x/wallet-adapter decoder types: AddressDecoder (EVM addresses) and TransactionDecoder (tx build/verify/broadcast).
manager
Package manager provides WalletManager: aggregates RPC client and chain config, handles nonce, gas, balance queries, and raw transaction broadcast for TransactionDecoder.
Package manager provides WalletManager: aggregates RPC client and chain config, handles nonce, gas, balance queries, and raw transaction broadcast for TransactionDecoder.
models
Package models defines internal data structures: TxFeeInfo, AddrBalance, CallMsg, etc., used by manager and decoder.
Package models defines internal data structures: TxFeeInfo, AddrBalance, CallMsg, etc., used by manager and decoder.
rpc
Package rpc provides Ethereum JSON-RPC client Client (Dial, Call), with read/write separation (broadcast uses BroadcastURL).
Package rpc provides Ethereum JSON-RPC client Client (Dial, Call), with read/write separation (broadcast uses BroadcastURL).
util
Package util provides common helpers: decimal conversion (delegates to wallet-adapter/amount) and address prefix Append0x.
Package util provides common helpers: decimal conversion (delegates to wallet-adapter/amount) and address prefix Append0x.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL