SDK
crossbell.js
Contract API
Initialize Contract

Initialize Contract

To interact with the blockchain, you need to use the contract. A contract is a collection of functions that can be called by other contracts or by users directly through wallets. The contract is the main building block of the blockchain.

import { Contract } from "crossbell.js";

Usage

Example 1: Connect with Metamask (Or Other Provider)

import { Contract } from 'crossbell.js'
 
// Create a new contract instance with metamask provider
const provider = window.ethereum
const contract = new Contract(provider)

You can also use other providers.

Example 2: Connect with Private Key

import { Contract } from 'crossbell.js'
 
const privateKey = '0xabcdef0123456789012345678901234567890123456789012345678901234'
const contract = new Contract(privateKey)

The private key is not stored in the contract. It is only used to sign the transaction.

However, you need to ensure that your private key is not exposed to the public for security reasons.

Example 3: Read-Only Contract

You can also connect with a read-only provider without passing anything into the Contract.

import { Contract } from 'crossbell.js'
 
const contract = new Contract();

In this case, you can't do write operations like createCharacter but only read operations like getCharacter.

Methods

Continue reading to learn more about the methods of the contract.