@nextdefihub/apps-react-sdk
v1.0.3
Published
React SDK for DefiHub Apps
Downloads
4
Readme
DefiHub Apps React SDK
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 acceptsloader
andoptions
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);