Use Openfort with Node.js
Learn how to get started with Openfort and mint an asset with NodeJS.
What you'll learn:#
- How to manage third-party dependencies using the npm or yarn package manager.
- How to install the latest Openfort Node SDK.
- How to send your first SDK request.
Set up a Openfort Node.js SDK
Open your project in the Openfort Dashboard.
The latest version of the Openfort Node.js server-side SDK supports Node.js versions 14+.
Declare Openfort Environment Variables
After your project is ready, grab your secret_key and public_key from the project.
Create a .env
file and populate with your project's secret key.
Also make sure to add the package.json file.
Add a contract to Openfort
In this tutorial, we'll use a simple ERC-721 contract on the Polygon Amoy network deployed at 0x252...43A.
Once added, Openfort will return a contract id that you can use to interact with the contract. It starts with con_
.
Prepare gas sponsorship
To offer gasless transaction (sponsor gas) in Openfort, your need to create a policy and a policy rule.
The policy rule will define the contract functions that you want to sponsor. In this example, we create a simple policy rule to pay for all user's interactions with the contract.
Grab your contract id and the policy id to include on your call.
Mint an NFT
Now mint an NFT using the contract id and the player id that you created in the previous steps.
Openfort will encode the transaction based on the provided information in the interaction.
The smart account will be created and deployed automatically for you on the Amoy network.
Because optimistic is set to false
, the response from creating the transactionIntents
will contain a response
.
Remember to replace the policy, contract and player ids with your own.
Run the script
You're all set! Run the development server on your Terminal.
You can check the logs and events of the transaction intent in your dashboard.