1.0.3 • Published 1 year ago

@nextdefihub/apps-react-sdk v1.0.3

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

DefiHub Apps React SDK

npm

This SDK should provide a simple way to write a React.js DefiHub App

How to use

  • Add npm package
yarn add @nextdefihub/apps-react-sdk

npm i @nextdefihub/apps-react-sdk
  • Add DefiHubProvider DefiHub provider accepts loader and options props
// ... other imports
import DefiHubProvider from "@nextdefihub/apps-react-sdk";

ReactDOM.render(
  <React.StrictMode>
    <DefiHubProvider>
      <App /> // Your app
    </DefiHubProvider>
  </React.StrictMode>,
  document.getElementById("root")
);
  • Use DefiHub Apps SDK Hook
// ... other imports
import { useDefiHubAppsSDK } from "@nextdefihub/apps-react-sdk";

const App = () => {
  const { sdk, connected, meta } = useDefiHubAppsSDK();
  return <div>{meta.account}</div>;
};

Usages

Send transactions

import { BaseTransaction } from "@nextdefihub/apps-sdk";

const txs: BaseTransaction[] = [
  {
    to: "0x31415629...",
    value: "0",
    data: "0xbaddad",
  },
  //...
];
// Returns a hash to identify the Meta transaction
const metaTxHash: string = await sdk.txs.send({ txs });

Load Meta transaction information

const metaTx: MetaTransaction = await sdk.txs.getByMetaTxHash(metaTxHash);
1.0.3

1 year ago

1.0.1

1 year ago