Authentication
ETHGas uses JWT Bearer token authentication. See Connect for the full login flow.
POST /v1/user/login
Get the EIP712 message for signing. Log in with your credentials.
- HTTP
- Python
curl -X POST "$ETHGAS_API_URL/v1/user/login?addr=0x8F02425B5f3c522b7EF8EA124162645F0397c478&name=username"
import requests
url = f"{ETHGAS_API_URL}/v1/user/login"
payload = {'addr': '0x5eF1B2c02f5E39C0fF667611C5d7EfFb0E7df305', 'name': 'username'}
headers = {'Content-Type': 'application/json'}
response = requests.post(url, headers=headers, params=payload)
print(response.text)
Request
| Parameter | Required | Type | Description |
|---|---|---|---|
| addr | YES | string | User's EOA account address |
| name | NO | string | Display name |
Response Body
| Name | Type | Description |
|---|---|---|
| status | string | Login status |
| eip712Message | object | EIP712 message to sign |
| nonceHash | string | Unique four-byte nonce for this login request |
Example Response
{
"success": true,
"data": {
"status": "verify",
"eip712Message": "{\"types\":{\"EIP712Domain\":[{\"name\":\"name\",\"type\":\"string\"}...],\"primaryType\":\"data\",\"message\":{\"hash\":\"52a90c73\",\"message\":\"Please sign this message to verify account ownership\",\"domain\":\"ethgas.com\"},\"domain\":{\"name\":\"ETHGas Login\",\"version\":\"1\",\"chainId\":32382,\"verifyingContract\":\"0x0000000000000000000000000000000000000000\"}}",
"nonceHash": "52a90c73"
}
}
Usage
Get the response from /v1/user/login, sign the eip712Message, and send the signed message to /v1/user/login/verify.
POST /v1/user/login/verify
Verify login by submitting the signed EIP712 message.
- HTTP
- Python
curl -X POST "$ETHGAS_API_URL/v1/user/login/verify?addr=0xe61f536f031f77C854b21652aB0F4fBe7CF3196F&nonceHash=517d9272&signature=0xc046037e..."
import requests
url = f"{ETHGAS_API_URL}/v1/user/login/verify"
payload = {
"addr": "0xe61f536f031f77C854b21652aB0F4fBe7CF3196F",
"nonceHash": "517d9272",
"signature": "0xc046037ec795f4cfe7aca33a0c283c0152bae91008b3e14b84be50f91f0e2db71..."
}
headers = {'Content-Type': 'application/json'}
response = requests.post(url, headers=headers, params=payload)
print(response.text)
Request
| Parameter | Required | Type | Description |
|---|---|---|---|
| addr | YES | string | User's EOA account address |
| nonceHash | YES | string | Nonce hash from login endpoint |
| signature | YES | string | Signed EIP712 message signature |
Response Body
| Name | Type | Description |
|---|---|---|
| user | object | User details |
| accessToken | object | JWT access token with token field |
Example 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": {
"token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
}
POST /v1/user/login/refresh
Get a new access token using a non-expired refresh token.
- HTTP
- Python
curl -X POST "$ETHGAS_API_URL/v1/user/login/refresh" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer {{access_token}}" \
-d '{"refreshToken": "your_refresh_token"}'
import requests
url = f"{ETHGAS_API_URL}/v1/user/login/refresh"
payload = {'refreshToken': 'your_refresh_token'}
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <current_access_token>'
}
response = requests.post(url, headers=headers, params=payload)
print(response.text)
Request
| Parameter | Required | Type | Description |
|---|---|---|---|
| refreshToken | YES | string | Refresh token |
Response Body
| Name | Type | Description |
|---|---|---|
| user | object | User details |
| accessToken | object | New access token |
POST /v1/user/logout
Log out the current session.
- HTTP
- Python
curl -H "Authorization: Bearer {{access_token}}" -X POST "$ETHGAS_API_URL/v1/user/logout"
import requests
url = f"{ETHGAS_API_URL}/v1/user/logout"
headers = {'Authorization': 'Bearer <your-auth-token>'}
response = requests.post(url, headers=headers)
print(response.text)
Request
No parameters for this endpoint.
Response Body
No response data for this endpoint.