Alchemy: How to Create and Mint an NFT using Filebase
Learn how to create and mint an NFT using Filebase and Alchemy.
NFTs, or ‘non-fungible tokens’ are crypto assets with varying values and attributes. NFTs can be anything from digital art, to music or pieces of writing. NFTs have associated metadata with them which includes a unique token that acts as a certificate of authenticity for the NFT. This token can be used for authentication similar to access and secret key pairs.
NFTs can be made by anyone, and ‘minted,’ or created and sold on blockchain networks, in exchange for cryptocurrency. The value of NFTs depends on a wide variety of factors, including crypto price, collection marketing, and investors, and the NFT community.
In this guide, we’ll take an image file stored on Filebase, a decentralized storage provider, and use Alchemy, a blockchain developer platform, to mint NFTs on the Ethereum blockchain.
- Create a folder of images you’d like to use as NFT images.
To do this, navigate to console.filebase.com. If you don’t have an account already, sign up, then log in.
Select ‘Create Bucket’ in the top right corner to create a new bucket for your NFTs.

Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.


Once uploaded, it will be listed in the bucket.

Choose the method you prefer, and take note of the IPFS CID. We will reference this later.

Select the ‘Create App’ button to get started.

Set the environment to ‘Staging’, the chain to ‘Ethereum’, and the network to ‘Göerli’.

This is so we aren’t dealing with actual currency.

mkdir my-nft
cd my-nft
These commands make a new folder, also referred to as a directory, then place us inside that directory.
npm init
This will initialize a new npm project in your
my-nft
directory. This command will output a list of prompts. Here’s how to answer them:
16. Now let’s install Hardhat, a development environment for us to deploy and test our Ethereum app on.
We can install Hardhat with the following command:
npm install --save-dev hardhat
Run the following command inside your
my-nft
directory:npx hardhat
It should return the following welcome message and menu prompt:

Run the following commands to add a
contracts
folder and a scripts
folder.mkdir contracts
mkdir scripts
Contracts will be for storing our NFT smart contracts, while scripts will be for storing the code used to mint and deploy our NFT.
Open your favorite IDE software and create a new file called
MyNFT.sol
. Copy and paste the following code into this new file://Contract based on https://docs.openzeppelin.com/contracts/3.x/erc721
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.3;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyNFT is ERC721, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() public ERC721("MyNFT", "NFT") {}
function mintNFT(address recipient, string memory tokenURI)
public onlyOwner
returns (uint256)
{
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(recipient, newItemId);
_setTokenURI(newItemId, tokenURI);
return newItemId;
}
}
npm install @openzeppelin/[email protected]
Every transaction using your Metamask wallet requires a signature using your Metamask private key. To use our Alchemy app, we need it’s API key. Since we will frequently need both of these keys, we’ll store them in an environment file. To do this, first install the
dotenv
package into the project directory with the following command:npm install dotenv --save
This file must be called .env, otherwise it will not work as expected.
Your .env file should look similar to this:
PRIVATE_KEY = "your-metamask-private-key"
API_URL = "https://eth-goerli.alchemyapi.io/v2/your-api-key"
npm install --save-dev @nomiclabs/hardhat-ethers "ethers@^5.0.0"
Update the
hardhat.config.js
file to reflect the following:/**
@type import('hardhat/config').HardhatUserConfig
/
require('dotenv').config();
require("@nomiclabs/hardhat-ethers");
const { API_URL, PRIVATE_KEY } = process.env;
module.exports = {
solidity: "0.7.3",
defaultNetwork: "ropsten",
networks: {
hardhat: {},
ropsten: {
url: API_URL,
accounts: [`0x${PRIVATE_KEY}`]
}
},
}
npx hardhat compile
Navigate to the
scripts
directory we made previously, then create a new file called deploy.js
with the following contents:async function main() {
// Grab the contract factory
const MyNFT = await ethers.getContractFactory("MyNFT");
// Start deployment, returning a promise that resolves to a contract object
const myNFT = await MyNFT.deploy(); // Instance of the contract
console.log("Contract deployed to address:", myNFT.address);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
Run the following command to use the
deploy.js
script:npx hardhat run scripts/deploy.js --network ropsten
This script will return something resembling the following output:
Contract deployed to address: 0x9C33cD8e20c595Aad0C04ae58414916e5529ff6a
To do this, first we need to install the Alchemy Web3 library. Install it in your project directory with the following command:
npm install @alch/alchemy-web3
require('dotenv').config();
const API_URL = process.env.API_URL;
const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
const web3 = createAlchemyWeb3(API_URL);
const contract = require("../artifacts/contracts/MyNFT.sol/MyNFT.json");
The NFT metadata allows for it to have properties such as NFT name, image, description, and other factors like collection and rarity.
In your project root directory, make a new file named
nft-metadata.json
with the following code:{
"attributes" : [ {
"trait_type" : "Type",
"value" : "Robot"
}, {
"trait_type" : "Color",
"value" : "Silver"
} ],
"description" : "An NFT of the Filebase Robot",
"image" : "https://ipfs.filebase.io/ipfs/[IPFS-CID]",
"name" : "Filebase Robot"
}
Replace the ‘image’ CID with your Filebase object IPFS CID from the beginning of this guide, and configure the other attributes such as trait_type, name, and description to reflect your desired configuration.
Copy the object’s IPFS CID and save it for reference later.
33. Head back to Etherscan where we confirmed that our contract was successfully created and copy down the contract’s address.
If you closed Etherscan, reopen it and search for your wallet address, then click on the transaction for your contract creation.

const contractAddress = "0x3a1952952b04aba42b9b7943e3b617e456dc9db4";
const nftContract = new web3.eth.Contract(contract.abi, contractAddress);
PUBLIC_KEY = "your-public-account-address"
const PRIVATE_KEY = process.env.PRIVATE_KEY;
async function mintNFT(tokenURI) {
const nonce = await web3.eth.getTransactionCount(PUBLIC_KEY, 'latest'); //get latest nonce
//the transaction
const tx = {
'from': PUBLIC_KEY,
'to': contractAddress,
'nonce': nonce,
'gas': 500000,
'maxPriorityFeePerGas': 1999999987,
'data': nftContract.methods.mintNFT(PUBLIC_KEY, tokenURI).encodeABI()
};
const signedTx = await web3.eth.accounts.signTransaction(tx, PRIVATE_KEY);
const transactionReceipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
console.log(`Transaction receipt: ${JSON.stringify(transactionReceipt)}`);
}
mintNFT("https://ipfs.filebase.io/ipfs/[IPFS-CID]");
These lines add a transaction function, sign the transaction with your private key, and log the transaction receipt. The last line uses the metadata file uploaded to Filebase when minting the NFT. Replace the IPFS-CID with the CID for this metadata file.
Overall, your
mint-nft.js
script should look like the following:require('dotenv').config();
const API_URL = process.env.API_URL;
const PUBLIC_KEY = process.env.PUBLIC_KEY;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
const web3 = createAlchemyWeb3(API_URL);
const contract = require("../artifacts/contracts/MyNFT.sol/MyNFT.json");
const contractAddress = "0x3a1952952b04aba42b9b7943e3b617e456dc9db4";
const nftContract = new web3.eth.Contract(contract.abi, contractAddress);
async function mintNFT(tokenURI) {
const nonce = await web3.eth.getTransactionCount(PUBLIC_KEY, 'latest'); //get latest nonce
//the transaction
const tx = {
'from': PUBLIC_KEY,
'to': contractAddress,
'nonce': nonce,
'gas': 500000,
'maxPriorityFeePerGas': 1999999987,
'data': nftContract.methods.mintNFT(PUBLIC_KEY, tokenURI).encodeABI()
};
const signedTx = await web3.eth.accounts.signTransaction(tx, PRIVATE_KEY);
const transactionReceipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
console.log(`Transaction receipt: ${JSON.stringify(transactionReceipt)}`);
}
mintNFT("https://ipfs.filebase.io/ipfs/[IPFS-CID]");
node scripts/mint-nft.js
You can confirm your transaction was successful by looking at your Alchemy Mempool and viewing the transaction status. If successful, it should have the status ‘Mined’.

Congratulations, you’ve successfully minted your first NFT! You can use this process to mint as many NFTs as you want! Just remember to use new metadata files for each transaction, otherwise you will create several duplicate NFTs.
If you have any questions, please join our Discord server, or send us an email at [email protected]
Last modified 7mo ago