Initial Setup

Implement Foresight API for your wallet.

In this series we'll implement an integration for both the Describe and Preview endpoints from the Foresight API, using simple Javascript code.

Initial Setup

Before we begin, make sure you have the axios and web3 libraries installed. If not, you can add it to your project using npm:

npm install axios
npm install web3

Next, import the library into your script:

const axios = require('axios');
const Web3 = require('web3');

Also, make sure you have your API key handy.

Get List of Chains

To get a list of EVM chains supported by the Foresight API, make a GET request to the /evm/chains endpoint.

const axios = require('axios');

const API_BASE_URL = 'https://foresight.noves.fi';

// Set your API Key as an env var or directly as a string
const NOVES_API_KEY = process.env.NOVES_API_KEY;

async function getSupportedChains() {
    try {
        const response = await axios.get(`${API_BASE_URL}/evm/chains`, {
            headers: {
                apiKey: NOVES_API_KEY,
            },
        });
        return response.data;
    } catch (error) {
        console.error('Error fetching supported chains:', error);
        return null;
    }
}

getSupportedChains().then((chains) => {
    console.log('Supported chains:', JSON.stringify(chains, null, 2));
});

This will give you the valid names for all chains supported in the API, along with some metadata.

Sample output:

  {
    "name": "polygon",
    "ecosystem": "evm",
    "evmChainId": 137
  }

The name field in this output is the one you'll be using to query our API. In this example, polygon.

Note on Foresight API input

Foresight takes as input an unsigned transaction object, which follows the standard format used by many wallets and decentralized applications.

In the coming pages, we'll assume that you already have an unsigned transaction to work with.

In most scenarios, such an object would be generated by the dApps that your users interact with.

If you want to have a sample transaction object to work with, refer to this tutorial to learn how to build one.