POST /register
: Registers a new user and creates an HD wallet for them.
- Body:
{
"username": "user",
"password": "password"
}
- Status:
201 Created
- Body:
{
"message": "User registered successfully"
}
POST /login
: Logs in a user and retrieves their wallet from MongoDB. Provides an access token for subsequent API requests.
- Body:
{
"username": "user",
"password": "password"
}
- Status:
200 OK
- Body:
{
"username": "user",
"address": "0xYourAddress",
"access_token": "your-access-token"
}
GET /getEthBalance
: Gets the Ethereum balance of a user login.
- Headers:
Authorization: Bearer your-access-token
- Status:
200 OK
- Body:
{
"address": "0xYourAddress",
"balance": "1.23456789"
}
Note: Replace your-access-token
with the actual token provided during the login process.
Example Flow:
-
The client includes the user's access token in the Authorization header as a bearer token.
-
The server decodes the token to extract user information, including the user ID.
-
The server looks up the user in the database using the decoded user ID to retrieve their wallet address associated with the account.
-
The server then queries the Ethereum blockchain or provider to get the Ethereum balance of the provided address.
-
The server responds with the user's Ethereum balance.
GET /getTokenBalance
: Gets the balance of a specific token for the authenticated user's wallet address.
- Headers:
Authorization: Bearer your-access-token
- Status:
200 OK
- Body:
{
"address": "0xYourAddress",
"balance": "1.23456789",
"decimal": "18",
"tokenName": "TokenName",
"tokenSymbol": "TokenSymbol"
}
Note: Replace your-access-token
with the actual token provided during the login process.
Example Flow:
-
The client includes the user's access token in the
Authorization
header as a bearer token. -
The server decodes the token to extract user information, including the user ID.
-
The server looks up the user in the database using the decoded user ID to retrieve their wallet address associated with the account.
-
The server retrieves the token contract address and ABI from configuration.
-
Using the Ethers library the server queries the token contract using the known tokenAddress to get the token balance of the user's wallet address.
-
The server responds with the user's token balance.
POST /sendEth
: Sends Ethereum from user login to another.
- Headers:
Authorization: Bearer your-access-token
- Body:
{
"toAddress": "0xRecipientAddress",
"amount": "1.2345"
}
- Status:
200 OK
- Body:
{
"transactionHash": "0xTransactionHash",
"message": "Transaction successful"
}
Note: Replace your-access-token
with the actual token provided during the login process.
Example Flow:
-
The client includes the user's access token in the
Authorization
header as a bearer token. -
The server decodes the token to extract user information, including the user ID.
-
The server looks up the user in the database using the decoded user ID to retrieve their wallet address associated with the account.
-
The server constructs a transaction to send Ethereum from the user's wallet address to the specified recipient's address.
-
The transaction is signed with the user's wallet private key.
-
The transaction is broadcasted to the Ethereum network.
-
The server responds with the transaction hash and a success message.
POST /sendToken
: Transfers tokens from the authenticated user's wallet to a specified recipient using a token contract. Please note that users need to have some Ether for gas fees.
- Headers:
Authorization: Bearer your-access-token
- Body:
{
"toAddress": "0xRecipientAddress",
"amount": "1.2345"
}
Note: Replace your-access-token
with the actual token provided during the login process.
- Status:
200 OK
- Body:
{
"transactionHash": "0xTransactionHash",
"message": "Transaction successful"
}
Example Flow:
-
The client includes the user's access token in the Authorization header as a bearer token.
-
The server decodes the token to extract user information, including the user ID.
-
The server looks up the user in the database using the decoded user ID to retrieve their wallet address associated with the account.
-
The server retrieves the token contract address and ABI from configuration.
-
The server constructs a transaction to transfer tokens from the user's wallet address to the specified recipient's address using the token contract.
-
The transaction is signed with the user's wallet private key.
-
The transaction is broadcasted to the Ethereum network.
-
The server responds with the transaction hash and a success message.
GET /estimateGasPrice
: Estimates the gas price for a transaction.
- No request parameters needed.
- Status:
200 OK
- Body:
{
"gasPrice": "10 Gwei"
}