Backend wallet with SDK (Node.js)
You can use backend wallets via Openfort's NodeJS Server SDK (or .net). Follow the instructions below to configure your desired integration.
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+.
mkdir openfort-tutorial
cd openfort-tutorial
npm init -y
npm install @openfort/openfort-node --save
touch index.js
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.
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.
const Openfort = require('@openfort/openfort-node').default;
const openfort = new Openfort(process.env.YOUR_SECRET_KEY);
const main = async () => {
// Create a new custodial backend wallet
const developerAccount = await openfort.settings.createDeveloperAccount({
name: "Minting Account"
});
console.log("Success! Here is your backend wallet id: " + developerAccount.id);
};
main().then(() => process.exit(0));
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_
.
curl https://api.openfort.io/v1/contracts \
-H "Authorization: Bearer $YOUR_SECRET_KEY" \
-d chainId=80002 \
-d address="0x2522F4Fc9aF2E1954a3D13f7a5B2683A00a4543A" \
-d abi=[
{
"inputs": [
{
"internalType": "address",
"name": "_to",
"type": "address"
}
],
"name": "mint",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
] \
-d name="Simple NFT"
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.
const Openfort = require('@openfort/openfort-node').default;
const openfort = new Openfort(process.env.YOUR_SECRET_KEY);
const main = async () => {
const developerAccount = await openfort.settings.createDeveloperAccount({
name: "Minting Account"
});
const contractId = "con_...";
const chainId = 80002;
const optimistic = false;
const tokenId = '1'; // Token ID to mint, should be unique
const interaction_mint = {
contract: contractId,
functionName: "mint",
functionArgs: [developerAccount.address, tokenId],
};
const transactionIntent = await openfort.transactionIntents.create({
"account": developerAccount.id,
"chainId": chainId,
"optimistic": optimistic,
"interactions": [interaction_mint]
});
console.log("Success! Here is your transactionIntent id: " + transactionIntent.id);
};
main().then(() => process.exit(0));
Run the script
You're all set! Run the development server on your Terminal.
You can check the transaction details in your dashboard.
npm run dev