0.1.0 • Published 5 years ago

@neo-react/invoker v0.1.0

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

@neo-react/invoker

React component that helps submitting a new transaction in order to invoke smart contracts.

Features

  • Using react context that allows easy state management and dispatch actions.
  • Support multiple wallets.
  • Support local storage (optional).

Demo

Click

Usage

import React from "react";
import NeoInvoker, { from "@neo-react/invoker";

const MyDapp = () => {
  return (
    <NeoInvoker useLocalStorage={true}>
        <SubComponent />
    </NeoInvoker>
  )
}

Then use context in child components

const SubComponent = () => {
  const { state, dispatch } = useContext(InvokerContext);
  /*
    Invoke using states and dispatches using your own way
  */
  return (
    <RenderState
      {...state}
    />
  );
};

Api

PropsTypeDefaultDescription
useLocalStoragebooleanfalseIt saves provider, encryptedKey and address key in user's local storage when they connect their wallet.

Context

State

KeyDescription
walletConnected wallet keys

Dispatch

MethodArgsDescription
dispatch.openInvoker()script: ScriptIt opens invoke confirmation modal.
dispatch.disconnectWallet()It remove the connected wallet from its state.
interface Script {
  transfer?: {
    from: string;
    to: string;
    amount: number;
    symbol: string;
  };
  operation: string;
  scriptHash: string;
  fee?: number;
  encodeArgs?: boolean;
  network?: "MainNet" | "TestNet" | "PrivateNet";
  args: InvokeScriptArgs[];
}