How to register a wallet

Whether you’re building a wallet, investing using smart contracts, or building out tax solutions, accessing high-quality financial-accounting data is critical to ensuring you’re accurately capturing both your and your user's activity and performance.

With OpenPool’s API. you can seamlessly access comprehensive contract & wallet accounting and reporting data for all your applications

Before you can start making API calls on wallet addresses, you will need to register your wallets. This is a simple POST request so let’s get started walking through how it works!

Before you get started

You will need an API key to start making requests, so let’s generate one from the OpenPool Developer Portal:

  1. Visit the Dev Portal at https://dev.openpool.co/

  2. Sign up or log in to your account

Untitled

  1. Create a Project and give it a name

Untitled

Awesome! Now that we have this covered, we can get to the good stuff - registering a 0x address (or multiple addresses) on OpenPool 🔥🔥🔥

Let’s get into it

For this example, we’ll be using Javascript to set up and make this request

First let’s get our request url

const url = 'https://api.openpool.co/wallet/manage/'

Now, let’s set up the request headers

  • Make sure you store your API key as an environment variable for security purposes
const headers = {
    accept: 'application/json',
    'content-type': 'application/json',
    'X-API-KEY': process.env.OPENPOOL_API_KEY //
  }

Now, let’s add the address(es) we want to register to the request body

  • If you’d like to register multiple addresses at once, just separate them by commas in a string.
const body = {
   address: `${<ADDRESS_TO_REGISTER>}, ${<ANOTHER_ADDRESS_TO_REGISTER>}`
}

Awesome, let’s put this all together to assemble our request options

const headers = {
    accept: 'application/json',
    'content-type': 'application/json',
    'X-API-KEY': '<YOUR_API_KEY>'
  }

const body = {
   address: `${<ADDRESS_TO_REGISTER>}, ${<ANOTHER_ADDRESS_TO_REGISTER>}`
}

const requestOptions = {
  method: 'POST',
  headers: headers
  body: JSON.stringify(body)
};

Finally, let’s set up our request in a function we can call registerAddress

  • In practice, you will likely want to use a more robust validation check here for the address
const registerAddress = async (address: string) => {
  if (!address || typeof address !== 'string' || address && typeof address === 'string' && !address.includes('0x')) {
    throw new Error('Invalid address');
    return
  }
  try {
     const url = 'https://api.openpool.co/wallet/manage/'
     const headers = {
       accept: 'application/json',
      'content-type': 'application/json',
      'X-API-KEY': '<YOUR_API_KEY>'
     }
    const body = {
       address: `${<ADDRESS_TO_REGISTER>}, ${<ANOTHER_ADDRESS_TO_REGISTER>}`
    }
    const requestOptions = {
      method: 'POST',
      headers: headers
      body: JSON.stringify(body)
    };

    const response = await fetch(url, requestOptions)
    const parsedResponse = response.json()
    return parsedResponse
  }
  catch(e){
      console.error(`The error trying to register an address`, ${e})
  }
}

Reading from the Response

When you receive a successful response, you will receive back an Object with a single property, results, which is an Array of Objects containing the registration statuses of each address that was sent in the request

{
  "results": [
    {
      "id": 48,
      "address": "0x59a5493513ba2378ed57ae5ecfb8a027e9d80365",
      "is_loaded": true
    }
  ]
}

Next Steps

Now that we have our addresses registered, we’re able to begin retrieving robust financial-accounting data for them. Follow along in the next article to learn how we can access the summarized profit & loss performance for registered wallet Tokens, NFTs, and DeFi balances.