5. Interaction
Last updated
Last updated
Ideally, interacting with your protected smart contract would be in conjunction with the frontend and backend - the user presses a button (i.e. does a transaction to your protected smart contract) which initiates a backend call, the frontend receives payload from it and proceeds to submit it to the blockchain.
But for the sake of simplicity, let's just create a simple nodejs application that executes a transaction on our protected function.
cube3_transaction_executer
nodejs application Let's start by creating a nodejs project using typescript.
create src/index.ts
file where we will write our implementation. Initially, add this inside:
We will need to access your protected contracts ABI
. So paste the file containing ABI
it into cube3_transaction_executer/src
.
Install CUBE3 packages:
First, import all necessary functions, Cube3ProtectedErc20
and setup constants:
The code below goes into generatePayload()
function.
At this point, we have the ability to call our protected contract. Let's move to payload generation.
These are the steps:
Pass it into constructCube3Validation
function which will extract the necessary data for payload generation.
In the previous step, we generated the payload for our protected mintCube3Protected
function. Now all that is left is to execute the transaction on the blockchain by passing the payload into the function call.
From the project root directory, in cmd run:
Lastly, you can analyze any protected transaction on the Panorama dashboard:
For blockchain interactions, we will use :
To generate a payload, you need to make an HTTP request to the CUBE3 validation service. For that, we will use . Let's begin.
For CUBE3 to generate a payload, it needs transaction data. For this, we will need to create a transaction object and pass it to .
For any interaction with a smart contract, we need to create a and objects.
Before we send an HTTP request to the CUBE3 validation endpoint, we need to generate transaction data without actually executing the transaction. For this, we are going to utilize ethers to create the transaction object which stores information about the transaction.
Send an HTTP request to the CUBE3 validation endpoint using cube3ValidateTransaction
function, which will return us whether this transaction is safe and the payload along with other information (to learn more about what the validation service returns, read more ). If CUBE3 finds that transaction to be unsafe/malicious, the payload will not be provided and the transaction will not be possible.
And the transaction receipt will appear. Copy the transaction hash and paste it into etherscan (for example sepolia) on which you should see a successful transaction, for example:
To learn more about the transaction dashboard, read .