Management API Reference

Server

Backend wallet with SDK (Node.js)

Use a backend wallet to mint an asset with NodeJS.

You can use backend wallets via Openfort's NodeJS Server SDK (or .net). Follow the instructions below to configure your desired integration.

1

Set up 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+.

Terminal

_10
mkdir openfort-tutorial
_10
cd openfort-tutorial
_10
npm init -y
_10
npm install @openfort/openfort-node --save
_10
touch index.js

2

Declare Openfort Environment Variables

After your project is ready, grab your secret_key from the project settings.

Create a .env file and populate it with your project's secret key.

.env

_10
YOUR_SECRET_KEY=sk_test_...

package.json

_16
{
_16
"name": "node",
_16
"version": "1.0.0",
_16
"description": "",
_16
"main": "index.js",
_16
"scripts": {
_16
"test": "echo \"Error: no test specified\" && exit 1",
_16
"dev": "node index.js"
_16
},
_16
"keywords": [],
_16
"author": "",
_16
"license": "ISC",
_16
"dependencies": {
_16
"@openfort/openfort-node": "^0.6.10"
_16
}
_16
}

3

Create a backend wallet

Backend wallet (dac) can be used for escrow, minting, and transferring assets. You can create a new custodial backend wallet or add your own external account by providing a signature and address.

index.js

_13
const Openfort = require('@openfort/openfort-node').default;
_13
const openfort = new Openfort(process.env.YOUR_SECRET_KEY);
_13
_13
const main = async () => {
_13
// Create a new custodial backend wallet
_13
const developerAccount = await openfort.settings.createDeveloperAccount({
_13
name: "Minting Account"
_13
});
_13
_13
console.log("Success! Here is your backend wallet id: " + developerAccount.id);
_13
};
_13
_13
main().then(() => process.exit(0));

4

Add a contract to Openfort

We'll use a simple ERC-721 contract on the Polygon Amoy network.

Once added, Openfort will return a contract id that starts with con_.

Terminal

_20
curl https://api.openfort.xyz/v1/contracts \
_20
-H "Authorization: Bearer $YOUR_SECRET_KEY" \
_20
-d chainId=80002 \
_20
-d address="0x2522F4Fc9aF2E1954a3D13f7a5B2683A00a4543A" \
_20
-d abi=[
_20
{
_20
"inputs": [
_20
{
_20
"internalType": "address",
_20
"name": "_to",
_20
"type": "address"
_20
}
_20
],
_20
"name": "mint",
_20
"outputs": [],
_20
"stateMutability": "nonpayable",
_20
"type": "function"
_20
}
_20
] \
_20
-d name="Simple NFT"

5

Mint an NFT using the backend wallet

Use your backend wallet to mint an NFT. The wallet will be used to pay for gas fees.

Make sure to replace the contract id with your own.

index.js

_30
const Openfort = require('@openfort/openfort-node').default;
_30
const openfort = new Openfort(process.env.YOUR_SECRET_KEY);
_30
_30
const main = async () => {
_30
const developerAccount = await openfort.settings.createDeveloperAccount({
_30
name: "Minting Account"
_30
});
_30
_30
const contractId = "con_...";
_30
const chainId = 80002;
_30
const optimistic = false;
_30
const tokenId = '1'; // Token ID to mint, should be unique
_30
_30
const interaction_mint = {
_30
contract: contractId,
_30
functionName: "mint",
_30
functionArgs: [developerAccount.address, tokenId],
_30
};
_30
_30
const transactionIntent = await openfort.transactionIntents.create({
_30
"account": developerAccount.id,
_30
"chainId": chainId,
_30
"optimistic": optimistic,
_30
"interactions": [interaction_mint]
_30
});
_30
_30
console.log("Success! Here is your transactionIntent id: " + transactionIntent.id);
_30
};
_30
_30
main().then(() => process.exit(0));

6

Run the script

You're all set! Run the development server on your Terminal.

You can check the transaction details in your dashboard.

Terminal

_10
npm run dev