Originally posted by **jac18281828** December 19, 2023
This request is to implement support for a memory hot wallet available to all request paths in `xps-gateway`. One of the common tasks supported by the `xps-gateway` will be implementation of subsidized transactions for EVM bound transactions. This can be handled by managing an internal wallet that supports a retrieval operation via the gateway RPC.
When `xps-gateway` starts it should spin up a memory hot wallet from a source of cryptographic quality entropy. This wallet should be shared across request paths to implement transaction fee payment. A gateway administrator should query the gateway for the wallet address. It may then optionally transfer ETH to the wallet for the payment of gas fees.
### Documentation for JSON RPC Endpoint: `walletAddress`
---
#### Endpoint Name: `walletAddress`
#### Description:
The `walletAddress` endpoint is designed to retrieve the Ethereum address associated with an in-memory wallet running on a server. This endpoint is crucial for applications requiring verification of wallet ownership or for initiating blockchain transactions.
#### Request:
- **Method:** `POST`
- **URL:** `/rpc/v1/walletAddress`
- **Headers:**
- `Content-Type: application/json`
- **Body:**
- **JSON Object:**
- `jsonrpc`: `"2.0"`
- `method`: `"walletAddress"`
- `params`: Array (optional parameters as required)
- `id`: Request identifier (integer or string)
**Example Request Body:**
```json
{
"jsonrpc": "2.0",
"method": "walletAddress",
"params": [],
"id": 1
}
```
#### Response:
- **Success Status Code:** `200 OK`
- **Error Status Codes:**
- `400 Bad Request` - Invalid request format or parameters.
- `500 Internal Server Error` - Server or wallet-related error.
**Success Response Body:**
```json
{
"jsonrpc": "2.0",
"result": {
"walletAddress": "0x1234567890abcdeF"
},
"id": 1
}
```
**Error Response Body:**
```json
{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "Invalid parameters"
},
"id": 1
}
```
#### Error Handling:
- **Invalid Parameters:** Check if the request body is properly formatted and includes valid parameters.
- **Wallet or Server Errors:** Ensure that the server and wallet are operational. Consult server logs for detailed error information.
#### Security Considerations:
- **Authentication and Authorization:** Implement authentication and authorization checks to ensure only authorized users can access wallet information.
- **Public Information Only:** Only public information is shared
- **Secure Communication:** Utilize HTTPS to encrypt data in transit and prevent eavesdropping.
#### Usage Example:
```javascript
const requestBody = {
jsonrpc: "2.0",
method: "walletAddress",
params: [],
id: 1
};
fetch('https://server.example.com/rpc/v1/walletAddress', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
})
.then(response => response.json())
.then(data => console.log('Wallet Address:', data.result))
.catch(error => console.error('Error:', error));
```
Discussed in https://github.com/xmtp/xps-gateway/discussions/8