Web3.js

Web3.js is a robust and flexible collection of TypeScript and JavaScript libraries that allows developers to interact with Lycan nodes over HTTP, IPC or WebSocket connections.

Check out web3js for installation details and an overview.

Initializing Web3.js with Lycan Chain

Once you have Web3.js installed, you need to set up a Web3 instance and connect it to the Lycan Chain network. Here’s how you can do it:

const Web3 = require('web3');

// Connect to the Lycan Chain RPC URL
const web3 = new Web3('https://rpc.lycanchain.com');

// Set default chain parameters
web3.eth.defaultCommon = {
    customChain: {
        name: 'Lycan',
        chainId: 721,
        networkId: 721
    }
};

This code initializes Web3.js and connects it to the Lycan Chain using the provided RPC URL. The defaultCommon parameter is configured to specify the custom chain details for Lycan Chain.

Interacting with Smart Contracts

Initializing a Contract

To interact with a smart contract on Lycan Chain, you'll need the contract's ABI (Application Binary Interface) and its deployed address. Here’s an example of how to initialize a contract:

// ABI of the smart contract
const contractABI = [
    // ABI details here
];

// Address of the deployed contract
const contractAddress = '0xYourContractAddressHere';

// Create a contract instance
const myContract = new web3.eth.Contract(contractABI, contractAddress);

Advanced Configuration

Custom Chain Configuration

By setting web3.eth.defaultCommon, you ensure that Web3.js is aware of the custom chain parameters for Lycan Chain. This is crucial for correctly signing transactions and interacting with the network.

web3.eth.defaultCommon = {
    customChain: {
        name: 'Lycan',
        chainId: 721,
        networkId: 721
    }
};

This configuration tells Web3.js to use the specified chain ID and network ID for all interactions, ensuring compatibility with Lycan Chain.

Last updated