npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hicaru/bearby.js

v0.5.8

Published

The web3 inject of bearby walet to access massa blockchain

Downloads

1,042

Readme

Introduction

The main web3 module of bearby wallet.

The following table provides a description of each module and what you may want to use it for.

| Package | Version | Description | Dependencies | | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | | @hicaru/bearby.js | npm | Core abstractions and base classes, such as ContentProvider and network logic for interfacing with the bearby wallet. | |

Installation

$ yarn # or npm install

run dev mode

$ yarn dev # or npm run dev

building

$ yarn build # or npm run build

Quick Start

In your project:

yarn add @hicaru/bearby.js # or npm install @hicaru/bearby.js

import (this script works only in the browser!)

import { web3 } from '@hicaru/bearby.js';

states:

import { web3 } from '@hicaru/bearby.js';

web3.contract // the instance for read, call, deploy contracts
web3.massa // JsonRPC methods connection to nodes.
web3.wallet // main statements of the wallet

web3.wallet:

  • web3.wallet.connected the bool type, false if user didn't connected to website.
  • web3.wallet.enabled the bool type, false if wallet locked.
  • web3.wallet.account the account object, has methods and properties about current address.
  • web3.wallet.network the network object, has methods and properties about current network.
  • web3.wallet.connect() the method, after call shows a popup with website information, user can approve or reject.
  • web3.wallet.signMessage("any message to sign") the method for sign any messages, shows a popup about message info.
  • web3.wallet.signTransaction(params) the method for sending transaction to network.
  • web3.wallet.isMassaAddress The method validation of massa base58 address

Account observer:

import { web3 } from '@hicaru/bearby.js';

/// Emit everytime when address been changed, or changed wallet status.
const observer = web3.wallet.account.subscribe((base58) => console.log(base58));

/// To avoid memory leak don't forget unsubscribe!!!
observer.unsubscribe();

Network observer:

import { web3 } from '@hicaru/bearby.js';

/// Emit everytime when network been changed.
const observer = web3.wallet.network.subscribe((net) => console.log(net))

/// To avoid memory leak don't forget unsubscribe!!!
observer.unsubscribe();

Contracts:

deploy

import { web3 } from '@hicaru/bearby.js';

 const hash = await bearby.contract.deploy({
    fee: 0,
    maxGas: 4_200_000_000,
    maxCoins: 0.1 * 10**9,
    coins: 100000000n,
    parameters: [
      {
        type: bearby.contract.types.STRING,
        value: "Hello, World!"
      }
    ],
    deployerBase64: "AGFzbQEAAAABWA9gAX8Bf2AAAGACf38AAAAAAAAAAAIAAAACAAAAA=",
    contractDataBase64: "AGFzbQEAAAABKQhgAX8AYAJ/fbWFw"
});

call

import { web3, ArgTypes } from '@hicaru/bearby.js';
const hash = await web3.contract.call({
  maxGas: 2000000,
  coins: 0,
  targetAddress: 'A12KqAUVvPZAAybdmJijkKbynfJeDUsfztEUh8JCSx6DPjczdYLt',
  functionName: 'transfer',
  parameters: [
    {
      type: ArgTypes.STRING,
      value: "Hello, World!"
    },
    {
      type: ArgTypes.BOOL,
      value: true
    },
    {
      type: globalThis.bearby.contract.types.F64,
      value: 32
    },
    {
      type: globalThis.bearby.contract.types.U256,
      value: '435435345234324324324323243242398854684'
    }
  ]
});

// UNSAFE_PARAMS:
import { Args } from "@massalabs/massa-web3";

const args = new Args()
  .addString("Hello word")
  .addBool(true)
  .addF64(0.3);
const hash = await web3.contract.call({
  maxGas: 2000000,
  coins: 0,
  targetAddress: 'A12KqAUVvPZAAybdmJijkKbynfJeDUsfztEUh8JCSx6DPjczdYLt',
  functionName: 'transfer',
  unsafeParameters: args.serialize()
});

read

import { web3, Args } from '@hicaru/bearby.js';

const data = await web3.contract.readSmartContract({
  fee: 0,
  maxGas: 200000,
  simulatedGasPrice: 0,
  targetAddress: 'A12KqAUVvPZAAybdmJijkKbynfJeDUsfztEUh8JCSx6DPjczdYLt',
  targetFunction: "balanceOf",
  parameter: []
});
console.log(data);

events

import { web3 } from '@hicaru/bearby.js';

const eventsFilter = {
  start: null,
  end: null,
  original_caller_address: null,
  original_operation_id: hash,
  emitter_address: null,
};
const response = await web3.contract.getFilteredSCOutputEvent(eventsFilter);

if (response && response.result && response.result[0] && response.result[0].data) {
  const contract = String(response.result[0].data).replace('Address:', '');
  console.log(contract);
}

Request pubkey.

import { web3 } from '@hicaru/bearby.js';

const pubkey = await web3.wallet.requestPubKey();

types

import { JsonRPCResponseExecuteReadOnlyBytecode } from '@hicaru/bearby.js/types';

const res?: JsonRPCResponseExecuteReadOnlyBytecode;