Setup
We provide a open source proxy server for developers who want to spin up a secure WaaS proxy server within minutes.
The following sections describe how to build and run a proxy server for the WaaS API.
Checkout the Code
waas-proxy-server is a proxy server for the WaaS API. It is designed to be easy to use and act as an intermediary between a client application and the WaaS API, while providing security for a developer's API keys.
You can checkout waas-proxy-server from GitHub by running the following command:
git clone https://github.com/coinbase/waas-proxy-server.git
Prerequisites
Configure
To configure the proxy server with your API key:
- Open the
.env
file. - Replace the
COINBASE_CLOUD_API_KEY_NAME
variable with thename
variable found in your API key file. - Replace the
COINBASE_CLOUD_API_KEY_PRIVATE_KEY
variable with theprivateKey
variable found in your API key file.
For example, if your .coinbase_cloud_api_key.json
API key file looks like the following:
{
"name": "organizations/{organizationID}/apiKeys/{apiKeyId}",
"principal": "{principalID}",
"principalType": "USER",
"publicKey": "-----BEGIN EC PUBLIC KEY-----\n{PUBLIC_KEY}\n-----END EC PUBLIC KEY-----\n",
"privateKey": "-----BEGIN EC PRIVATE KEY-----\n{PRIVATE_KEY}\n-----END EC PRIVATE KEY-----\n",
"createTime": "2023-03-21T02:02:45.362863508Z"
}
Your .env
file would look like:
COINBASE_CLOUD_API_KEY_NAME=organizations/{organizationID}/apiKeys/{apiKeyId}
COINBASE_CLOUD_API_KEY_PRIVATE_KEY="-----BEGIN EC PRIVATE KEY-----\n{PRIVATE_KEY}\n-----END EC PRIVATE KEY-----\n"
GRPC_ADDRESS=0.0.0.0:8090
HTTP_ADDRESS=0.0.0.0:8091
To see hidden files (i.e. .env
) in your Mac Finder, press Command+Shift+Dot.
Running the Proxy Server
Once the proxy server has been configured, you can build and run it by using make, including targets for Docker.
Using make
Build the proxy server:
make waas-proxy-server
Run the proxy server:
make run
Docker
Build the proxy server:
make docker/build
Run the proxy server:
make docker/run
Calling the Proxy Server
Once the proxy server is running, you can make requests to it using your desired endpoint.
The proxy server is set to listen on localhost:8091
by default. You can specify your desired host and port by modifying HTTP_ADDRESS
in the .env
file.
Using curl
# Calls ListNetworks
curl -X GET -d '{}' localhost:8091/v1/networks
Using JavaScript
/* Calls ListNetworks */
fetch('http://localhost:8091/v1/networks', {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
.then(response => {
if (!response.ok) {
throw new Error()
}
return response.json()
})