MetaMask Mobile provides functionality to log API calls, which is useful for debugging and testing purposes. This feature is available for all build types.
The recommended way to monitor API calls is to use the dedicated API monitoring script. This provides detailed logging of all API requests and responses.
You can enable API call logging by setting the LOG_API_CALLS=true
environment variable when starting the app:
LOG_API_CALLS=true yarn start:ios
# or
LOG_API_CALLS=true yarn start:android
# or any other build variant
- Open a new terminal window
- Run the following command:
yarn start:api-logging-server
The monitor will start and display:
- The port it's running on
- Detailed logs for all API calls including:
- Request method and URL
- Request headers
- Request body
- Response status code and message
- Response headers
- Response body
To stop the API monitor, press Ctrl+C
in the terminal where it's running.
For E2E tests, API logging is automatically enabled. You don't need to set any additional environment variables.
The API call logging functionality is implemented using the following components:
- A fetch interceptor in
shim.js
that routes all API calls through a proxy - The
LOG_API_CALLS
environment variable that enables this functionality - For E2E tests, this is automatically enabled by the
isTest
condition - The API monitor script uses
mockttp
to intercept and log all API calls
When using the API monitor, you'll see detailed logs in the console showing:
- All API requests with their methods, URLs, headers, and bodies
- All API responses with their status codes, headers, and bodies
- Pretty-formatted JSON for better readability
This is particularly useful for:
- Debugging API-related issues
- Understanding the network traffic of the app
- Verifying that API calls are being made correctly