Use Openfort with Node.js
Learn how to get started with Openfort and mint an asset with NodeJS.
In this quickstart, 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.
After your project is ready, grab your secret_key and public_key from the project.
The latest version of the Openfort Node.js server-side SDK supports Node.js versions 14+.
Run your first SDK request
Open the newly created index.js
file and add the following code to it.
This will create a new player in your project amnd return the player id that you can use to interact with its underlying account.
Declare Openfort Environment Variables
Create a .env
file and populate with your project's secret key.
Add a contract to Openfort
In this tutorial, we'll use a simple ERC-721 contract on the Mumbai network deployed at 0x380...AC0.
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 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. To create a policy rule, you need to know the contract id that you created in the previous step as well as the policy.
Mint an NFT
You're all set! Now you can 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 inreaction.
An account will be created and deployed automatically for you on the Mumbai network.
Because optimistic is set to false
, the response from creating the transactionIntents
will contain a response
.
Run the script
Run the development server