Crossfi RPC and API Setup Guide

Crossfi RPC and API Setup Guide

Domain and DNS Settings (This is optional)

When acquiring a domain, you may choose various providers, but the key step is to move your domain to a Cloudflare account for enhanced performance, security, and DNS management. Here's how to transfer your GoDaddy-purchased domain to Cloudflare:

  1. Create a Cloudflare Account: Go to Cloudflare's website and sign up. After creating your account, click "Add a Site" to start adding your domain to Cloudflare.

  2. Add Your Sites to Cloudflare: Enter the name of your site and click "Add Site". Cloudflare will attempt to automatically fetch your site's DNS records. Review and, if necessary, manually add any missing DNS records. Cloudflare will offer to manage your DNS records at this stage.

  3. Obtain New Name Server Information from Cloudflare: After adding your site and verifying your DNS records, Cloudflare will provide two name server (NS) addresses. These are Cloudflare's DNS servers, which will handle DNS queries for your site.

  4. Log In to Your GoDaddy Account: Go to the "My Products" section. Find the domain you wish to manage and navigate to its settings.

  5. Update Name Server Settings in GoDaddy: In the domain settings, click on "DNS Management" or "Manage DNS". Click "Change" or "Edit" to update your current NS records to the addresses provided by Cloudflare.

  6. Save the New Name Server Addresses: After entering the new name server addresses from Cloudflare, save the changes. It may take some time for the changes to propagate across the internet (usually within 24 hours, but sometimes longer).

  7. Complete Processes in Cloudflare and GoDaddy: Follow the necessary steps in Cloudflare to ensure the name server changes are correctly implemented. Wait for the verifications to complete on both platforms.

Note: DNS changes may not take effect immediately. Wait until the propagation process is complete. If you encounter any errors, you can contact the support teams of both Cloudflare and GoDaddy.

Remember, I have set up my explorer on a different server and the Crossfi node on another. You should accordingly prepare your domain and subdomains as shown in the image below.

Settings in your domain

First create subdomains like crossfi-api, crossfi-rpc, crossfi-jsonrpc and make them A record with your server ip.

Installing Dependencies and Setting Up Nginx

Connect to your Crossfi Node and execute the following commands to install Nginx:

sudo apt -q update
sudo apt -qy install curl git jq lz4 build-essential snapd unzip nginx
sudo apt -qy upgrade

API Nginx Configuration File Creation

Create a configuration file for your API:

sudo nano /etc/nginx/sites-available/crossfi-api

Inside the file, it's time to enter the necessary configuration for your API subdomain. Below is a template designed specifically for a Node.js application. Make sure you understand each directive and modify it to fit the specific needs of your application, especially the proxy_pass directive, which should point to the port your application is running on:

server {
    listen 80;
    server_name crossfi-api.elessarnodes.xyz;

    location / {
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Max-Age 3600;
        add_header Access-Control-Expose-Headers Content-Length;
        
        proxy_pass http://0.0.0.0:1317;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Replace elessarnodes.xyz with your domain in the server_name section, and adjust the port number in the proxy_pass directory if necessary (default is 1317). This setup instructs the server to listen on port 80, the default for HTTP. The server_name should match your project's subdomain. The proxy_pass directive is crucial as it tells NGINX where to route requests entering this subdomain.

Creating Your RPC Nginx Configuration File

Similarly, create a configuration for your RPC:

sudo nano /etc/nginx/sites-available/crossfi-rpc
server {
    listen 80;
    server_name crossfi-rpc.elessarnodes.xyz;

    location / {
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Max-Age 3600;
        add_header Access-Control-Expose-Headers Content-Length;
        
        proxy_pass http://0.0.0.0:26657;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Enter the configuration, replacing elessarnodes.xyz with your domain and adjusting the proxy_pass for your RPC port (default is 26657).

Creating Your Evm rpc Nginx Configuration File

sudo nano /etc/nginx/sites-available/crossfi-jsonrpc
server {
    listen 80;
    server_name crossfi-jsonrpc.elessarnodes.xyz;

    location / {
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Max-Age 3600;
        add_header Access-Control-Expose-Headers Content-Length;
        
        proxy_pass http://0.0.0.0:8545;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Enter the configuration, replacing elessarnodes.xyz with your domain and adjusting the proxy_pass for your RPC port (default is 8545).

Activating Your Configuration

After tailoring the configuration file to your needs and saving your changes, the next step is to link this file to the sites-enabled directory to activate it:

sudo ln -s /etc/nginx/sites-available/crossfi-* /etc/nginx/sites-enabled/

This command creates a symbolic link between the sites-available and sites-enabled directories, effectively activating your configuration.

Finally, test your NGINX configuration for syntax errors:

sudo nginx -t

If the test passes without issues, reload NGINX to apply the changes:

sudo systemctl reload nginx

Your subdomains should now be set up and accessible via the specified subdomain addresses. This setup enhances the structure of your project by creating a clear distinction between different parts of your application, facilitating developers and users to interact with your endpoints.

However, all your endpoints are still using unsecure HTTP. In the next section, we'll install SSL for all our endpoints.

Installing CertBot

We will use CertBot as our SSL manager. Install it using the following commands:

sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo snap set certbot trust-plugin-with-root=ok

SSL Configuration

Configure SSL:

sudo certbot --nginx --register-unsafely-without-email

Editing the app.toml File

Change the indicated false to true.

If everything is done correctly, your API and RPC links should now be working as follows:

https://crossfi-api.elessarnodes.xyz/

https://crossfi-rpc.elessarnodes.xyz/

For evm rpc, enter this command in your server and it should give an output curl -X POST https://crossfi-jsonrpc.elessarnodes.xyz -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

Last updated