Ethereum (ETH) Exchange Wallet Development: Withdrawal Request Process

·

Overview

The withdrawal process in an Ethereum exchange wallet follows a specific sequence. This guide builds upon the previous installment, "Ethereum (ETH) Exchange Wallet Development: Deposit Address Generation", which covered API request validation. The same validation middleware (using Gin framework) applies here.

Withdrawal Request Parameters

ParameterDescription
SymbolRequired. Currently only "eth" supported
OutSerialRequired. Unique identifier (max 40 chars) to prevent duplicate requests
AddressRequired. Recipient's Ethereum address
BalanceRequired. Amount to withdraw

Key Considerations

  1. OutSerial Field:

    • Database enforces uniqueness via index
    • Prevents duplicate processing of identical withdrawal requests

Validation Process

1. Address Validation

req.Address = strings.ToLower(req.Address)
re := regexp.MustCompile("^0x[0-9a-fA-F]{40}$")
if !re.MatchString(req.Address) {
    c.JSON(http.StatusOK, gin.H{
        "error":   hcommon.ErrorAddressWrong,
        "err_msg": hcommon.ErrorAddressWrongMsg,
    })
    return
}

👉 Best practices for Ethereum address validation

2. Amount Validation

balanceObj, err := decimal.NewFromString(req.Balance)
if err != nil {
    hcommon.Log.Errorf("err: [%T] %s", err, err.Error())
    c.JSON(http.StatusOK, gin.H{
        "error":   hcommon.ErrorBalanceFormat,
        "err_msg": hcommon.ErrorBalanceFormatMsg,
    })
    return
}

if balanceObj.LessThanOrEqual(decimal.NewFromInt(0)) {
    c.JSON(http.StatusOK, gin.H{
        "error":   hcommon.ErrorBalanceFormat,
        "err_msg": hcommon.ErrorBalanceFormatMsg,
    })
    return
}

if balanceObj.Exponent() < -18 {
    c.JSON(http.StatusOK, gin.H{
        "error":   hcommon.ErrorBalanceFormat,
        "err_msg": hcommon.ErrorBalanceFormatMsg,
    })
    return
}

Post-Validation Process

After successful validation:

  1. Data gets inserted into the database
  2. The withdrawal processing system takes over (as described in "Ethereum (ETH) Exchange Wallet Development: Withdrawal Processing")

Implementation Details

The complete implementation is available on GitHub:
https://github.com/moremorefun/go-dc-wallet

Main functionality entry point: cmd/api/main.go

👉 Secure Ethereum wallet development strategies

FAQ

Q: Why is address case conversion necessary?

A: Ethereum addresses are case-insensitive. Converting to lowercase ensures consistent validation and storage.

Q: What happens if duplicate OutSerial is submitted?

A: The database uniqueness constraint will reject the transaction, preventing duplicate withdrawals.

Q: What's the maximum decimal precision for ETH?

A: Ethereum supports up to 18 decimal places (1 Wei = 10^-18 ETH).

Q: How are negative withdrawal amounts prevented?

A: The validation explicitly checks that the amount is greater than zero.

Q: Where does the process go after successful validation?

A: The withdrawal gets queued for processing by the system described in part 4 of this series.