0.5.8 • Published 1 month ago

@hicaru/bearby.js v0.5.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

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.

PackageVersionDescriptionDependencies
@hicaru/bearby.jsnpmCore 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;
0.5.8

1 month ago

0.5.7

2 months ago

0.5.6

3 months ago

0.5.5

4 months ago

0.5.4

4 months ago

0.5.3

4 months ago

0.5.2

4 months ago

0.5.1

4 months ago

0.4.9

8 months ago

0.4.8

9 months ago

0.4.7

10 months ago

0.4.6

10 months ago

0.5.0

8 months ago

0.4.5

1 year ago

0.4.4

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.9

1 year ago

0.3.8

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.7

1 year ago

0.3.2

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago