Cover photo

Side Protocol. Guide to getting started

1. Introduction

Side Protocol is a modular framework designed to facilitate seamless cross-chain transactions and decentralized applications. This guide will help you set up, interact with the protocol, and understand its key functionalities.


2. Setting Up Your Environment

To work with Side Protocol, ensure you have the following:

Prerequisites:

  • Operating System: Linux, macOS, or Windows with WSL.

  • Programming Language: Node.js v16+.

  • Package Manager: Yarn or npm.

  • Blockchain Tools: hardhat, ethers.js.

Install Dependencies:

  1. Install Node.js from nodejs.org.

  2. Install Yarn globally:

    npm install -g yarn
    
  3. Verify installation:

    node -v
    yarn -v
    

3. Cloning the Repository

Clone the repository to your local machine:

git clone https://github.com/sideprotocol/side.git
cd side

4. Building and Running the Project

Install Project Dependencies

Run the following to install dependencies:

Compile Contracts

If the project uses Solidity smart contracts, compile them with Hardhat:

yarn hardhat compile

Run Tests

Ensure everything works by running the tests:

yarn test

5. Key Features and Interactions

Feature 1: Deploying Contracts

Deploy a contract using the Hardhat framework:

Example: Deploying a Simple Contract

deploy.js:

const { ethers } = require("hardhat");

async function main() {
    const MyContract = await ethers.getContractFactory("MyContract");
    const myContract = await MyContract.deploy();
    await myContract.deployed();

    console.log("Contract deployed to:", myContract.address);
}

main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});

Run the script:

yarn hardhat run scripts/deploy.js --network localhost

Feature 2: Interacting with Contracts

Use ethers.js to interact with deployed contracts.

Example: Reading and Writing

const { ethers } = require("ethers");

// Connect to the network
const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545");

// Define contract details
const contractAddress = "0xYourDeployedContractAddress";
const abi = [
    "function getValue() public view returns (uint256)",
    "function setValue(uint256 _value) public"
];

// Create a signer
const signer = provider.getSigner();

// Connect to the contract
const myContract = new ethers.Contract(contractAddress, abi, signer);

// Read data
async function readData() {
    const value = await myContract.getValue();
    console.log("Value:", value.toString());
}

// Write data
async function writeData() {
    const tx = await myContract.setValue(42);
    await tx.wait();
    console.log("Value updated!");
}

readData();
writeData();

Feature 3: Cross-Chain Transactions

The protocol facilitates cross-chain operations using relayers. To configure:

  1. Update config.js to specify supported chains and relayer endpoints.

  2. Use provided SDKs for cross-chain messaging:

Example: Cross-Chain Token Transfer

const { SideProtocol } = require("side-sdk");

async function crossChainTransfer() {
    const sdk = new SideProtocol({ network: "mainnet" });
    
    const tx = await sdk.transfer({
        fromChain: "Ethereum",
        toChain: "Polygon",
        token: "0xTokenAddress",
        amount: ethers.utils.parseUnits("10", 18),
        recipient: "0xRecipientAddress"
    });

    console.log("Transaction Hash:", tx.hash);
}

crossChainTransfer();

6. Testing and Debugging

  • Debugging Tips:

    • Use console.log() or Hardhat's built-in debugging tools.

    • Check logs in logs/ or transaction receipts.

  • Testing: Use Hardhat to write unit tests for smart contracts. Example:

test/MyContract.test.js:

const { expect } = require("chai");

describe("MyContract", function () {
    it("Should set the correct value", async function () {
        const MyContract = await ethers.getContractFactory("MyContract");
        const myContract = await MyContract.deploy();
        await myContract.deployed();

        await myContract.setValue(42);
        expect(await myContract.getValue()).to.equal(42);
    });
});

Run tests:

yarn hardhat test