Giter Site home page Giter Site logo

birdgg / crossbell.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from crossbell-box/crossbell.js

0.0 1.0 0.0 8.62 MB

Crossbell.js - A JavaScript SDK to interact with Crossbell

Home Page: https://Crossbell-Box.github.io/crossbell.js

License: MIT License

JavaScript 1.03% TypeScript 98.97%

crossbell.js's Introduction

crossbell.js

A JavaScript SDK to interact with the Crossbell. It works for both browser and Node.js.

npm version npm downloads

Installation

npm install crossbell

Usage

Requirements

Node.js >= 18.0.0 or Node.js >= 16.14.0 with fetch polyfill

Contract

Connect with Metamask

import { createContract } from 'crossbell'

// Create a new contract instance with metamask provider
const provider = window.ethereum
const contract = new createContract(provider)

// Example API: Create a new character for an address
try {
  const result = await contract.character.create({
    owner: '0x1234567890123456789012345678901234567890',
    handle: 'Jason',
    metadataOrUri: 'ipfs://xxxx/metadata.json',
  })
  console.log(result.data) // '42' (characterId)
  console.log(result.transactionHash) // '0xabcdef...'
} catch (e) {
  console.error(e.message) // e.g. "execution reverted: Web3Entry: HandleExists"
}

Connect with Private Key

You can also connect with a private key directly.

import { createContract } from 'crossbell'

const privateKey =
  '0xabcdef0123456789012345678901234567890123456789012345678901234'
const contract = new createContract(provider)

Connect with Read-Only

You can also connect with a read-only provider. Note that in this case, you can't do write operations like createCharacter.

import { createContract } from 'crossbell'

const contract = new createContract(provider) // just pass nothing to use a read-only provider

For more contract api, see docs.

Indexer

You can fetch data from the crossbell indexer.

import { createIndexer } from 'crossbell'

const indexer = createIndexer()

// get a list of characters owned by a specific address
const res = await indexer.character.getMany(
  '0x1234567890123456789012345678901234567890',
)
console.log(res.list)

For more indexer api, see docs.

crossbell.js's People

Contributors

songkeys avatar sxzz avatar renovate[bot] avatar birdgg avatar runjuu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.