1.0.3 • Published 4 months ago

@energy8/massa-provider v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

Energy8 Wallet massa-provider

Implementation of Energy8 web3 wallet to access the massа chain

@energy8/massa-provider is a TypeScript library to easily connect frontend applications with browser energy8 wallet extension and massa blockchain.

Installation

npm install @energy8/massa-provider

or

yarn add @energy8/massa-provider

Usage

import (this script works only in the browser!)

import { web3 } from '@energy8/massa-provider';

(async () => {
    const Web3 = await web3
})()

Promise<IMassaProvider>

Promise<boolean>

boolean

boolean

string

data:
  type: Buffer | Uint8Array | string

Promise<IAccountSignOutput>

{
  "publicKey": "...",
  "base58Encoded": "..."
}
amount:
  type: bigint
fee:
  type: bigint

Promise<ITransactionDetails>

{
  "operationId": "B1t..."
}
amount:
  type: bigint
fee:
  type: bigint

Promise<ITransactionDetails>

{
  "operationId": "B1t..."
}
amount:
  type: bigint
recipientAddress:
  type: string
fee:
  type: bigint

Promise<ITransactionDetails>

{
  "operationId": "B1t..."
}
contractAddress:
  type: string
functionName:
  type: string
parameter:
  type: Uint8Array
amount:
  type: bigint
fee:
  type: bigint 
maxGas:
  type: bigint

Promise<ITransactionDetails>

{
  "operationId": "B1t..."
}

Example

import {web3} from '@energy8/massa-provider'

(async () => {
    const Web3 = await web3
    await Web3.wallet.connect()

    console.log('connected', Web3.wallet.connected)

    //base58 address string
    console.log('connected', Web3.wallet.account.address())

    /**
     * {finalBalance: string, candidateBalance: string}
     */
    console.log('balance', Web3.wallet.account.balance())

    /**
     * state locked/unlocked wallet extension
     */
    console.log('unlocked', Web3.wallet.unlocked)

    /**
     * returned ITransactionDetails
     * {operationId: string}
     */
    console.log('unlocked', Web3.wallet.account.buyRolls(
        10n,
        10n,
    ))

    /**
     * returned ITransactionDetails
     * {operationId: string}
     */
    console.log('execSC', Web3.contract.execSmartContract(
        'AU166n9NvYrSGfMoXAPnwD4hXyLzZchJHj1TUkWwBEae8L3X8MwB',
        'someFunctionName',
        new Uint8Array([4,   0,   0,   0, 116, 101, 115, 116]),
        10n,
        10n,
        100000000n
    ))
})();
1.0.3

4 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago