This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const faker = require('faker'); | |
const TOTAL = 4; | |
const folderCIDForImages = "YOUR_IMAGE_FOLDER_CID"; | |
const gatewayCustomDomain = "YOUR_CUSTOM_GATEWAY_DOMAIN" | |
const generateRandomMetadata = (id) => { | |
return { | |
name: faker.name.findName(), | |
description: faker.lorem.sentences(), | |
image: `${gatewayCustomDomain}/ipfs/${folderCIDForImages}/${id}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PinataJWT = "YOUR PINATA JWT"; | |
const fs = require("fs"); | |
const axios = require("axios"); | |
const FormData = require("form-data"); | |
const recursive = require("recursive-fs"); | |
const basePathConverter = require("base-path-converter"); | |
async function main() { | |
try { | |
const path = "./YOUR_FOLDER_PATH_RELATIVE_TO_PROJECT_ROOT"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getApiConfig = async () => { | |
const config = { | |
headers: { | |
Authorization: `Bearer ${PinataJWT}`, | |
} | |
}; | |
return config; | |
}; | |
export const handleUpload = async (selectedFiles, customName, wrapWithDirectory) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We require the Hardhat Runtime Environment explicitly here. This is optional | |
// but useful for running the script in a standalone fashion through `node <script>`. | |
// | |
// When running the script with `npx hardhat run <script>` you'll find the Hardhat | |
// Runtime Environment's members available in the global scope. | |
const hre = require("hardhat"); | |
const BASE_URI = ""; | |
async function main() { | |
// Hardhat always runs the compile task when running scripts with its command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("@nomiclabs/hardhat-waffle"); | |
// This is a sample Hardhat task. To learn how to create your own go to | |
// https://hardhat.org/guides/create-task.html | |
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => { | |
const accounts = await hre.ethers.getSigners(); | |
for (const account of accounts) { | |
console.log(account.address); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { expect } = require("chai"); | |
const { ethers } = require("hardhat"); | |
const BASE_URI = "ipfs://FAKE_IPFS_CID/"; | |
const TEST_WALLET = "0x243dc2F47EC5A0693C5c7bD39b31561cCd4B0e97"; | |
describe("PFPinatas", function () { | |
it("Should mint a new token", async function () { | |
const PFPinata = await ethers.getContractFactory("PFPinatas"); | |
const pfpPinata = await PFPinata.deploy(BASE_URI); | |
await pfpPinata.deployed(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// contracts/PFPinatas.sol | |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
import "@openzeppelin/contracts/utils/Strings.sol"; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
contract PFPinatas is ERC721 { | |
using Strings for uint256; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// contracts/GameItem.sol | |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
contract GameItem is ERC721URIStorage { | |
using Counters for Counters.Counter; | |
Counters.Counter private _tokenIds; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { init, mint_to, get_token_uri, get_token_owner, grant_access, check_access, revoke_access, transfer_from } from '../main'; | |
import { VMContext } from "near-sdk-as"; | |
const ALICE = 'alice' | |
const BOB = 'bob' | |
const CAROL = 'carol' | |
const METADATA_URI = 'ipfs://QmTUj7kVQLxvnK8adcVhRV3GR9xxrtmHXddtKJT8AM9MqP' | |
describe("Initializing Contract", () => { | |
it("should not allow init to be called after contract is deployed", () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function mint_to(owner_id: AccountId, metadata_uri: MetadataUri): u64 { | |
const tokenId = storage.getPrimitive<u64>(TOTAL_SUPPLY, 1) | |
assert(tokenId <= MAX_SUPPLY, ERROR_MAXIMUM_TOKEN_LIMIT_REACHED) | |
tokenToOwner.set(tokenId, owner_id) | |
tokenToMetadata.set(tokenId, metadata_uri) | |
storage.set<u64>(TOTAL_SUPPLY, tokenId + 1) |