@cube3/sdk-ui
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

sdk-data

SDK-UI is used your DAPP's frontend. For you to do any transaction validations, you need to create an abstraction of that transaction. This SDK allows you to do so on the frontend level.

Example

  1. In the DApp frontend, initialize a contract and connect it to a signer
import { ethers } from "ethers";

const signer = provider.getSigner();

const yourTokenContract = new ethers.Contract(
yourContractAddress,
yourContractAbi,
signer
);

const connectedTokenContract = yourTokenContract.connect(signer);
  1. Let’s populate transaction with a transfer method for validation. First, import our CUBE3 frontend library and create CUBE3 validation object. For that - use constructCube3Validation method that takes in two parameters - populatedTransaction object (Make sure to set chainId and value field, where value field is amount of ether being interacted with in the blockchain) and a boolean trackNonce used to determine whether to track nonce. But before pas
import {constructCube3Validation} from '@cube-web3/sdk-ui'

//Our previous code <...>

const txData = await connectedTokenContract.populateTransaction.transfer("to", amount)

//make sure to have your chainId and value defined inside this object
txData.chainId = 5;
txData.value = BigNumber.from(0);

const cube3TransactionData = await constructCube3Validation(txData, true);
  1. Send CUBE3 data to the DApp (your) backend with cube3TransactionData in the request body.
const requestParams = {
  method: "POST",
  body: JSON.stringify(cube3TransactionData)
}

const validationFetch = await fetch('<...>/api/validation', requestParams)```

Now to do the actual validation in your backend, use https://www.npmjs.com/package/@cube3/sdk-nodejs.

Readme

Keywords

none

Package Sidebar

Install

npm i @cube3/sdk-ui

Weekly Downloads

17

Version

1.1.3

License

MIT

Unpacked Size

10.2 kB

Total Files

8

Last publish

Collaborators

  • cube3