Figment Datahub and Celo Network: Create an ERC1155 NFT on the Celo Network using Figment Datahub and Objects Stored on Filebase
Learn how to create a ERC1155 NFT on the Celo Network using Figment Datahub and objects stored on Filebase.
ERC1155 is a novel token standard that aims to take the best from previous standards to create a fungibility-agnostic and gas-efficient token contract. ERC1155 draws ideas from all of ERC20, ERC721, and ERC777. ERC1155s are commonly used in NFT collectible projects, although they are not typically viewed as 'fine art' it is not unreasonable to use this token standard for such purposes.
Celo is a global payment infrastructure platform for cryptocurrencies that targets mobile device end users.
Figment DataHub is a platform that enables developers to create decentralized applications (dApps) using the powerful and unique features of blockchain technology without having to be experts on the wide variety of blockchain protocols.
This guide was written and tested using Ubuntu 20.04. Commands and workflow may vary depending on your operating system.

Then use the ‘Create App’ button to create your new Celo app.

We will reference this API key later.

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.

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.

Set up a credentials file for S3FS at
${HOME}/.passwd-s3fs.
You will need to save your Filebase Access and Secret keys to this file and give it owner permissions. You can do so with the following commands:
echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fs
chmod 600 ${HOME}/.passwd-s3fs
ACCESS_KEY_ID is your Filebase Access key, and SECRET_ACCESS_KEY is your Filebase Secret key. For more information on Filebase access keys, see here.
You can mount a Filebase IPFS bucket with the command:
s3fs mybucket /path/to/mountpoint -o passwd_file=${HOME}/.passwd-s3fs -o url=https://s3.filebase.com
- mybucket: name of your Filebase bucket
- /path/to/mountpoint
cd /path/to/mounted/bucket
mkdir nftcollection
cd nftcollection
npm init
npm install --save-dev hardhat
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers web3 @celo/contractkit
npx hardhat
During the Hardhat initialization, select ‘Create a sample project’.
npm install @openzeppelin/contracts
touch contracts/NFTCollection.sol
This command also creates a new file called
NFTCollection.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
contract NFTCollection is ERC1155 {
// TODO
}
uint256 public constant CLOUD = 0;
uint256 public constant BUTTON = 1;
uint256 public constant ROBOT = 2;
For example, for the CLOUD NFT with an ID of 0, we would create 0.json with the following content:
{
"name": "Cloud",
"description": "Filebase Cloud",
"image": "https://ipfs.filebase.io/ipfs/{IPFS-CID}"
}
Replace the
{CID}
with the CID associated with the image uploaded to your Filebase bucket.constructor() ERC1155("/local/path/to/json/files/{id}.json") {
}
//If you do not have a Cloud the contract will let you buy one
function mintVillage() public{
require(balanceOf(msg.sender,CLOUD) == 0,"you already have a Cloud ");
_mint(msg.sender,CLOUD,1,"0x000");
}
//If you do not have a Button and have a Cloud the contract will let you buy the Button
function mintMine() public{
require(balanceOf(msg.sender,CLOUD) > 0,"you need to have a Cloud");
require(balanceOf(msg.sender,BUTTON) == 0,"you already have a Button");
_mint(msg.sender,BUTTON,1,"0x000");
}
//If you do not have a Robot and have a Cloud the contract will let you buy the Robot
function mintFarm() public{
require(balanceOf(msg.sender,CLOUD) > 0,"you need to have a Cloud");
require(balanceOf(msg.sender,ROBOT) == 0,"you already have a Robot");
_mint(msg.sender,ROBOT,1,"0x000");
}
module.exports = {
solidity: "0.8.0",
};
This file will interfere with the contract file we created when we compile it.
npx hardhat compile
Create a new file called
celo_account.js
with the following content:const Web3 = require('web3')
const fs = require('fs')
const path = require('path')
const web3 = new Web3()
const privateKeyFile = path.join(__dirname, './.secret')
// Function getAccount will return the address of your account
const getAccount = () => {
const secret = fs.readFileSync(privateKeyFile);
const account = web3.eth.accounts.privateKeyToAccount(secret.toString())
return account;
}
// Function setAccount will create new account and save the privateKey in .secret file
const setAccount = () => {
const newAccount = web3.eth.accounts.create()
fs.writeFileSync(privateKeyFile, newAccount.privateKey, (err) => {
if (err) {
console.log(err);
}
})
console.log(`Address ${newAccount.address}`)
}
module.exports = {
getAccount,
setAccount
}
const fs = require('fs')
const path = require('path')
const privateKeyFile = path.join(__dirname, './.secret')
const Account = require('./celo_account');
Then under the existing tasks in that file, insert the following task:
task("celo-account", "Prints account address or create a new", async () => {
fs.existsSync(privateKeyFile) ? console.log(`Address ${Account.getAccount().address}`) : Account.setAccount();
});
In this file, insert the following code:
const Web3 = require('web3')
const ContractKit = require('@celo/contractkit')
const web3 = new Web3('https://celo-alfajores--rpc.datahub.figment.io/apikey/Datahub CELO API Key/')
const kit = ContractKit.newKitFromWeb3(web3)
const data = require('./artifacts/contracts/NFTCollection.sol/NFTCollection.json')
const Account = require('./celo_account');
async function NFTCollection() {
const account = Account.getAccount()
kit.connection.addAccount(account.privateKey)
let tx = await kit.connection.sendTransaction({
from: account.address,
data: data.bytecode
})
return tx.waitReceipt()
}
module.exports = {
NFTCollection
}
Replace the DataHub CELO API Key with the Figment DataHub API key we took note of at the beginning of this tutorial.
const Deploy = require('./celo_deploy');
task("celo-deploy", "Prints account address or create a new", async () => {
const tx = await Deploy.NFTCollection();
console.log(tx);
console.log(`save the contract address ${tx.contractAddress}`)
});
npx hardhat celo-deploy
This will return your contract address.
From here, you can use this contract to interact with your NFT. You can use it in an application, such as a React App, that allows users to interact with your NFT collection through a user interface. Check out an example React App here.
If you have any questions, please join our Discord server, or send us an email at [email protected]