1.1.1 • Published 3 days ago

@bywise/provider v1.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 days ago

Bywise Web3 Provider

Contributors Welcome!

Hello, this is a relatively simple library that connects websites with the Bywise blockchain. If you have some basic working JS/TS knowledge, please head over to the open bugs/enhancements and help clear the backlog. Thanks in advance! 🤠

Please don't forget to join our discord community.


Installation

npm install @bywise/provider

I also recommend installing @bywise/web3.

npm install @bywise/web3

Usage

Require in javascript as

const BywiseProvider = require('@bywise/provider');

For typescript, use

import BywiseProvider from '@bywise/provider';

Operations

New instance

const chain = 'mainnet' // select your chain (default: mainnet)
const provider = new BywiseProvider(chain);

Connect provider

const userInfo = await provider.connect();

if (userInfo) { 
  const userAddress = provider.address;
  const connectedChain = provider.chains;

  // Provider connected successfully
} else {
  // User canceled the connection
}

Get User Blockchain Information

const infoBlockchainUser = await provider.web3.wallets.getWalletInfo(provider.address, chain);

console.log('infoBlockchainUser', infoBlockchainUser)
if (infoBlockchainUser) {
  const balance = infoBlockchainUser.balance // BWS Balance
  const name = infoBlockchainUser.name // can be null
  const url = infoBlockchainUser.url // can be null
  const bio = infoBlockchainUser.bio // can be null
  const photo = infoBlockchainUser.photo // can be null
} else {
  // Failed get info
}

Make simple transaction

import { TxType } from '@bywise/web3';

const sendAddress = 'BWS000000000000000000000000000000000000000000000';
const sendBWSAmount = '0';

const result = await provider.send({
  to: [sendAddress],
  amount: [sendBWSAmount],
  type: TxType.TX_NONE,
  data: {}
});
if (result) {
  const tx = result.tx; // full transaction
  const fullOutput = result.output; // full result output
  
  const contractReturn = fullOutput.output;
  console.log('contractReturn', contractReturn)
} else {
  // canceled transaction
}

Read contract

const contractAddress = 'BWS000000000000000000000000000000000000000000000';
const contractMethodName = 'someMethod';
const parameters = []; // string list

const fullOutput = await provider.web3.contracts.readContract(chain, contractAddress, contractMethodName, parameters);
if(fullOutput.error) {
    console.log('error', fullOutput.error)
} else {
    const contractReturnValue = fullOutput.output;
    console.log('contractReturnValue', contractReturnValue)
}

Write contract

import { TxType } from '@bywise/web3';

const contractAddress = 'BWS000000000000000000000000000000000000000000000';
const sendBWSToContract = '0';

const result = await provider.send({
  to: [contractAddress],
  amount: [sendBWSToContract],
  type: TxType.TX_CONTRACT_EXE,
  data: [
    {
      method: 'someMethod',
      inputs: ['arg1' , 'ar2'],
    },
  ]
});
if (result) {
  const tx = result.tx; // full transaction
  const fullOutput = result.output; // full result output

  const contractReturn = fullOutput.output;
  console.log('contractReturn', contractReturn)
} else {
  // canceled transaction
}
1.1.1

3 days ago

1.1.0

3 days ago

1.0.9

4 days ago

1.0.8

1 month ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

0.10.0

9 months ago