1.1.5 • Published 6 months ago

@cube3/sdk-nodejs v1.1.5

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

Example

DApp's backend

we can ask CUBE3 to validate transaction for us using cube3ValidateTransaction method from @cube3/sdk-nodejs library. For that, you need to set your apiKey, validationUrl.

import { cube3ValidateTransaction, Cube3Api, Cube3ValidationData } from '@cube-web3/sdk-nodejs'
import { ethers } from "ethers";

export class ValidationController {
    public static async validateTransaction(req: Request, res: Response) {
        const apiKey = "<...>"
        const validationUrl = "https://<...>/api/transaction/validate"

        const cube3ValidationData: Cube3ValidationData = {
            transactionData: req.body,
            clientIp: req.ip
        }

        const validation = await cube3ValidateTransaction(validationUrl, apiKey, cube3ValidationData)

        return res.status(200).send(JSON.stringify(cube3ValidationResponse))
    }
}

This is what validation returns

interface Cube3ValidationResponse {
    valid: boolean
    payload?: string
    error?: string
    combinedScore: number
    cube3TxId: string
}

After sending the transaction to the chain, we will save the transaction ID to the system. To do so, you will need a transaction ID and an internal CUBE3 transaction ID. However, we cannot do that on frontend because our API-KEY would get exposed. So, we will call dApp’s backend with receipt hash and internal CUBE3 transaction ID in body.

import { cube3ValidateTransaction, Cube3ValidationData } from '@cube3/sdk-nodejs'
import { ethers } from "ethers";

export class ValidationController {
    public static async saveTransaction(req: Request, res: Response) {
        const apiKey: "<...>",
        const saveTransactionUrl: "https://<...>/api/transaction"

        const transactionId = req.body.transactionId
        const cube3TxId = req.body.cube3TxId

        const response = await cube3SaveTransaction(saveTransactionUrl, apiKey, transactionId, cube3TxId)
        return res.status(200).send(JSON.stringify(response))
    }
}
1.1.1

7 months ago

1.1.0

7 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago