Skip to main content

Connecting to ETHGas

TestNet (Hoodi) and MainNet. Use TestNet first.

Prerequisites​


  • API Credentials: You'll need to register an account on ETHGas Exchange
  • Environment Selection: Choose between TestNet (Hoodi) or MainNet
  • Network Access: Ability to connect to ETHGas endpoints

Development Workflow​


✅ Start with TestNet - Develop and test your integration

✅ Validate Functionality - Ensure all features work correctly

✅ Test with Real Data - Use TestNet's simulated real data

✅ Deploy to MainNet - Move to production when ready

info

The JWT access token is valid for 1 hour; after each hour, a refresh is required.
Include the JWT in the request header: Authorization: 'Bearer accessToken'.
A private session is valid for 7 days; after 7 days, re-login is required.
For WebSocket, include the access token in the session header: Bearer accessToken.

Authentication Workflow​

For interacting with /v1 endpoints, a login is required. The login workflow is as follows: See lang tabs

  1. Get Login Message: Call the endpoint /v1/user/login with the appropriate addr to get the login sign message.

  2. Sign and Verify: Sign the login message and call the endpoint /v1/user/login/verify with the addr, nonceHash, and signature. You will receive the JWT access token, as well as user-related data, and can now call any private endpoints.

  3. Refresh Token: Before the access token expires, call /v1/user/login/refresh to get a new access token.

Connecting to ETHGas​


🔓 Public (/v1/p)
These endpoints provide access to market data, order book snapshots, trade history, and more — information available to all users. They are open and do not require authentication, so you can retrieve real-time market data for analysis or display.
🔒 Private (/v1)
These endpoints require authentication and provide access to account-specific information and trading functionality.
  1. Get Login Message: Call the endpoint /v1/user/login with the appropriate addr to get the login sign message.

  2. Sign and Verify: Sign the login message and call the endpoint /v1/user/login/verify with the addr, nonceHash, and signature. You will receive the JWT access token, as well as user-related data, and can now call any private endpoints.

  3. Refresh Token: Before the access token expires, call /v1/user/login/refresh to get a new access token.

Environments​

EnvironmentChainRPC URLChain IDAPI base URLWebsocket base URLCollateral Contract
MainnetEthereum Chainhttps://eth.llamarpc.com1https://mainnet.app.ethgas.com/apiwss://mainnet.app.ethgas.com/ws0x3314Fb492a5d205A601f2A0521fAFbD039502Fc3
TestnetHoodi Chainhttps://ethereum-hoodi-rpc.publicnode.com560048https://hoodi.app.ethgas.com/apiwss://hoodi.app.ethgas.com/ws0x104Ef4192a97E0A93aBe8893c8A2d2484DFCBAF1
  • Chain IDs are shown in decimal (e.g. Hoodi testnet is 560048, hex 0x88BB0).
  • User can get a list of mainnet rpc urls from https://chainlist.org/chain/1

Configuration​

# Mainnet
ETHGAS_API_URL=https://mainnet.app.ethgas.com/api
ETHGAS_WS_URL=wss://mainnet.app.ethgas.com/ws

# Testnet (Hoodi)
ETHGAS_API_URL=https://hoodi.app.ethgas.com/api
ETHGAS_WS_URL=wss://hoodi.app.ethgas.com/ws

Endpoint paths in this documentation (e.g. /v1/user/login, /v1/builder/register) are relative to ETHGAS_API_URL. The full URL is $ETHGAS_API_URL + path (e.g. https://mainnet.app.ethgas.com/api/v1/user/login).

REST API​

Response Structure​

Every API response contains a success flag and a response body.

NameTypeDescription
successbooleanAPI call is successful or unsuccessful
dataobjectResponse body

Authentication Flow​

ETHGas uses JWT Bearer token authentication as mentioned above. Here's the complete flow:

Login

First, authenticate with your credentials to get the EIP712 message for signing.

Example Code:

curl -X POST "$ETHGAS_API_URL/v1/user/login?addr=0x8F02425B5f3c522b7EF8EA124162645F0397c478&name=username"

Example Response:

{
"success": true,
"data": {
"nonceHash": "0x...",
"eip712Message": "{...}"
}
}

Request Parameters:

ParameterRequiredTypeDescription
addrYESstringUser's EOA account (account) address
nameNOstringDisplay name

Response Body:

NameTypeDescription
statusstringLogin status
eip712MessageobjectEIP712 message
nonceHashstringA unique four-byte nonce to identify this particular login request

Usage

Get the response from /v1/user/login and sign the eip712Message and send the signed message through /v1/user/login/verify.

Verify Login

After receiving the EIP712 message from the login endpoint, sign it and send the signature to verify your account ownership.

Example Code:

curl -X POST "$ETHGAS_API_URL/v1/user/login/verify?addr=0xe61f536f031f77C854b21652aB0F4fBe7CF3196F&nonceHash=517d9272&signature=0xc046037ec795f4cfe7aca33a0c283c0152bae91008b3e14b84be50f91f0e2db714054dee85b840e3edf0e26480231a684447f48337de64ea6697a3552aa9351a1b"

Response:

{
"success": true,
"data": {
"user": {
"userId": 78,
"address": "0xe61f536f031f77c854b21652ab0f4fbe7cf3196f",
"status": 1,
"userType": 1,
"userClass": 1,
"accounts": [
{
"accountId": 242,
"userId": 78,
"type": 1,
"name": "Current",
"status": 1,
"updateDate": 1698127521000
},
{
"accountId": 243,
"userId": 78,
"type": 2,
"name": "Preconf",
"status": 1,
"updateDate": 1698127521000
}
]
},
"accessToken": {
"data": {
"header": {
"alg": "ES256",
"typ": "JWT"
},
"payload": {
"user": {
"userId": 78,
"address": "0xe61f536f031f77c854b21652ab0f4fbe7cf3196f",
"roles": [
"ROLE_USER"
]
},
"access_type": "access_token",
"iat": 1698633225,
"exp": 1698636825
}
},
"token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVzZXJJZCI6NzgsImFkZHJlc3MiOiIweGU2MWY1MzZmMDMxZjc3Yzg1NGIyMTY1MmFiMGY0ZmJlN2NmMzE5NmYiLCJyb2xlcyI6WyJST0xFX1VTRVIiXX0sImFjY2Vzc190eXBlIjoiYWNjZXNzX3Rva2VuIiwiaWF0IjoxNjk4NjMzMjI1LCJleHAiOjE2OTg2MzY4MjV9.E3aIKqqFsHVBYedAuqn6Jw6bymsWy6RQ6gf_lDXnYNorjngA05uFLaTM0A2ZrN4kJ8nTXEjlrdhLU8crisJcdA"
}
}
}

Request Parameters:

ParameterRequiredTypeDescription
addrYESstringUser's EOA account address
nonceHashYESstringThe nonce hash received from the login endpoint
signatureYESstringThe signed EIP712 message signature

Response Body:

NameTypeDescription
accessTokenobjectJWT access token with token and expiresAt fields
refreshTokenstringToken used to refresh the access token
userobjectUser account information

Usage

Sign the EIP712 message received from /v1/user/login and send the signature along with the nonceHash to /v1/user/login/verify to complete authentication and receive your access token.

Token Refresh
curl -X POST "$ETHGAS_API_URL/v1/user/login/refresh" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <current_access_token>" \
-d '{"refreshToken": "your_refresh_token"}'
Logout
POST /v1/user/logout
Authorization: Bearer <access_token>

Response:

{
"success": true,
"data": {
"message": "Logged out successfully"
}
}

WebSocket Connection​

For real-time data, establish a WebSocket connection:

WebSocket URL: wss://hoodi.app.ethgas.com/ws

Configuration:

ETHGAS_WS_URL=wss://hoodi.app.ethgas.com/ws

Environment: Testnet (Hoodi)
Purpose: Development, testing, and integration
Data: Simulated market data and test transactions

WebSocket Authentication​

Authenticate your WebSocket connection:

{
"cmd": "login",
"args": {
"accessToken": "YOUR_ACCESS_TOKEN"
}
}

WebSocket Message Structure​

All WebSocket messages follow this format:

{
"cmd": "command_name",
"args": {
"parameter1": "value1",
"parameter2": "value2"
}
}

Common WebSocket Commands​

CommandDescription
loginAuthenticate the connection
subscribeSubscribe to real-time updates
unsubscribeUnsubscribe from updates
queryRequest specific data

Infrastructure​

Relay Endpoints​

Official relay endpoints by region:

RegionEnvironmentEndpoint
TokyoMainnethttps://0x88ef3061f598101ca713d556cf757763d9be93d33c3092d3ab6334a36855b6b4a4020528dd533a62d25ea6648251e62e@ap-relay.ethgas.com
TokyoHoodihttps://0xb20c3fe59db9c3655088839ef3d972878d182eb745afd8abb1dd2abf6c14f93cd5934ed4446a5fe1ba039e2bc0cf1011@hoodi-relay.ethgas.com
FrankfurtMainnethttps://0x88ef3061f598101ca713d556cf757763d9be93d33c3092d3ab6334a36855b6b4a4020528dd533a62d25ea6648251e62e@eu-relay.ethgas.com
VirginiaMainnethttps://0x88ef3061f598101ca713d556cf757763d9be93d33c3092d3ab6334a36855b6b4a4020528dd533a62d25ea6648251e62e@us-relay.ethgas.com

Prepend the key as shown in the endpoint URLs for authentication.

Error Handling​

ETHGas uses standard HTTP status codes and custom error codes. See the Error Codes section for details.

Next Steps​