nft
Skill18 starsChanged 17 days agoMITView on GitHub
Build shielded and unshielded NFTs on Midnight using OpenZeppelin Compact contracts and native Midnight token functions. Covers NonFungibleToken (ERC721-like), minting, transfers, metadata, and privacy preserving patterns.
- Pipes a download into a shell
2 other projects use a version of this.
Adopted by
Most recently taken up by
- aibtcdev/skillstheir own version, first seen Oct 26, 2026
- tusharpamnani/Midnight-Skillsword for word, first seen May 2, 2026
Other versions2 projects use a version of this.
Word for word · 1
- tusharpamnani/Midnight-Skills★ 1100% same
Edited · 0
None found.
Wrote their own version · 1
- aibtcdev/skills★ 11same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository36 other files it gives its agents.
- AGENTS.mdAGENTS.md
- 1am-walletSkill
- android-example-votingSkill
- ankr-midnightSkill
- compactSkill
- dynamic-midnight-walletSkill
- example-counterSkill
- example-hello-worldSkill
- example-leaderboard-dappSkill
- example-locker-dappSkill
- example-passport-dappSkill
- example-payment-dappSkill
- example-private-party-dappSkill
- example-private-reserve-auction-dappSkill
- example-zk-loan-applicationSkill
- gsap-coreSkill
- gsap-utilsSkill
- indexerSkill
- midnight-consensusSkill
- midnight-cryptographySkill
- midnight-environment-setupSkill
- midnight-jsSkill
- midnight-onchain-logicSkill
- midnight-p2p-networkingSkill
- midnight-passportSkill
- midnight-rpcSkill
- midnightskillSkill
- midnight-storageSkill
- midnight-transactionsSkill
- multinetworkSkill
- react-wallet-connectorSkill
- midnight-securitySkill
- testingSkill
- token-transfersSkill
- why-midnightSkill
- zk-vs-fhe-vs-mpcSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 9
Place files exactly as shown:
- Very specific: line 20
Add to PATH: source $HOME/.local/bin/env
- Distinctive: line 155
Use the Compact standard library's shielded token functions:
- Distinctive: line 250
Confidential ownership: When who owns the NFT should remain private
- Distinctive: line 252
Compliance-by-design: Only reveal ownership when required
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Scope This skill covers NFT development on Midnight Network. It includes the OpenZeppelin NonFungibleToken contract (ERC721-like implementation in Compact) and native Midnight token operations (shielded/unshielded). Covers minting, transfers, approvals, metadata URIs, and privacy patterns for NFTs.
Place files exactly as shown:
contracts/NonFungibleToken.compact→ OpenZeppelin base contractcontracts/MyNFT.compact→ your custom NFT contracttest/→ contract unit tests
1) Installation
Prerequisites
- Node.js v22.15+
- Compact devtools:
curl --proto '=https' --tlsv1.2 -sSf https://github.com/midnightntwrk/compact/releases/latest/download/compact-installer.sh | sh - Add to PATH:
source $HOME/.local/bin/env
Add OpenZeppelin Contracts for Compact
mkdir my-nft-project && cd my-nft-project
git init
git submodule add https://github.com/OpenZeppelin/contracts-compact.git
cd contracts-compact && SKIP_ZK=true yarn && cd ..2) OpenZeppelin NonFungibleToken Contract
The OpenZeppelin NonFungibleToken module provides an ERC721-like implementation in Compact.
Key Features
| Feature | Status | Notes |
| Token ID type | Uint<128> | Uint256 not supported (circuit limits) |
| Transfers | ✅ | To ECDSA public keys or contract addresses |
| Approvals | ✅ | Per-token and operator approvals |
| Metadata URI | ✅ | Per-token URI storage |
| Pausable | ✅ | Through Pausable module |
| Ownable | ✅ | Through Ownable module |
| Contract-to-contract | ❌ | Not yet supported (use _unsafeTransfer) |
Import and Use
pragma language_version >= 0.21.0;
import CompactStandardLibrary;
import "./contracts-compact/node_modules/@openzeppelin-compact/contracts/src/access/Ownable"
prefix Ownable_;
import "./contracts-compact/node_modules/@openzeppelin-compact/contracts/src/security/Pausable"
prefix Pausable_;
import "./contracts-compact/node_modules/@openzeppelin-compact/contracts/src/token/NonFungibleToken"
prefix NonFungibleToken_;
constructor(
_name: Opaque<"string">,
_symbol: Opaque<"string">,
_initOwner: Either<ZswapCoinPublicKey, ContractAddress>,
) {
Ownable_initialize(_initOwner);
NonFungibleToken_initialize(_name, _symbol);
}
export circuit mint(
to: Either<ZswapCoinPublicKey, ContractAddress>,
tokenId: Uint<128>,
uri: Opaque<"string">,
): [] {
Ownable_assertOnlyOwner();
NonFungibleToken__mint(to, tokenId);
NonFungibleToken__setTokenURI(tokenId, uri);
}
export circuit transferFrom(
from: Either<ZswapCoinPublicKey, ContractAddress>,
to: Either<ZswapCoinPublicKey, ContractAddress>,
tokenId: Uint<128>,
): [] {
Pausable_assertNotPaused();
NonFungibleToken_transferFrom(from, to, tokenId);
}
export circuit approve(
to: Either<ZswapCoinPublicKey, ContractAddress>,
tokenId: Uint<128>,
): [] {
NonFungibleToken_approve(to, tokenId);
}
export circuit setApprovalForAll(
operator: Either<ZswapCoinPublicKey, ContractAddress>,
approved: Boolean,
): [] {
Ownable_assertOnlyOwner();
NonFungibleToken_setApprovalForAll(operator, approved);
}
export circuit pause(): [] {
Ownable_assertOnlyOwner();
Pausable__pause();
}
export circuit unpause(): [] {
Ownable_assertOnlyOwner();
Pausable__unpause();
}3) Native Midnight NFT Patterns
Midnight's standard library provides native token functions for shielded/unshielded operations.
Unshielded NFT (Public)
import CompactStandardLibrary;
export ledger nextTokenId: Uint<128>;
export ledger owners: Map<Uint<128>, Either<ZswapCoinPublicKey, ContractAddress>>;
export ledger tokenURIs: Map<Uint<128>, Opaque<"string">>;
export circuit mint(
to: Either<ZswapCoinPublicKey, ContractAddress>,
uri: Opaque<"string">,
): Uint<128> {
const tokenId = nextTokenId;
nextTokenId += 1;
owners.insert(disclose(tokenId), disclose(to));
tokenURIs.insert(disclose(tokenId), disclose(uri));
return tokenId;
}
export circuit transfer(
from: Either<ZswapCoinPublicKey, ContractAddress>,
to: Either<ZswapCoinPublicKey, ContractAddress>,
tokenId: Uint<128>,
): [] {
const owner = owners.lookup(disclose(tokenId));
assert(owner == disclose(from), "Not owner");
owners.insert(disclose(tokenId), disclose(to));
}
export circuit tokenURI(tokenId: Uint<128>): Opaque<"string"> {
return tokenURIs.lookup(disclose(tokenId));
}Shielded NFT (Private Ownership)
Use the Compact standard library's shielded token functions:
import CompactStandardLibrary;
// Mint a shielded NFT
export circuit mintShielded(
to: ZswapCoinPublicKey,
metadataHash: Field,
): Uint<128> {
const tokenId = nextTokenId;
nextTokenId += 1;
// Store commitment to ownership + metadata
const commitment = persistentCommit<Uint<128>>(tokenId, freshNonce());
shieldedCommitments.insert(disclose(to), commitment);
return tokenId;
}
// Transfer shielded NFT (prove ownership without revealing tokenId publicly)
export circuit transferShielded(
tokenId: Uint<128>,
newOwner: ZswapCoinPublicKey,
): [] {
// Use ZK proof to demonstrate ownership
// Owner's shielded wallet signs the transfer
const oldCommitment = shieldedCommitments.lookup(disclose(callerPublicKey()));
assert(oldCommitment != default<Field>(), "Not owner");
shieldedCommitments.remove(disclose(callerPublicKey()));
shieldedCommitments.insert(disclose(newOwner), oldCommitment);
}4) Compile the Contract
cd contracts
compact compile MyNFT.compact artifacts/MyNFTExpected output:
Compiling 5 circuits:
circuit "mint" (k=11, rows=1180)
circuit "transferFrom" (k=11, rows=1966)
circuit "approve" (k=10, rows=966)
circuit "pause" (k=10, rows=125)
circuit "unpause" (k=10, rows=121)
Overall progress [====================] 5/55) Deploy and Interact (TypeScript)
import { CompiledContract } from '@midnight-ntwrk/compact-js';
import { deployContract } from '@midnight-ntwrk/midnight-js-contracts';
import { Contract } from './contracts/managed/MyNFT';
const compiledContract = CompiledContract.make('MyNFT', Contract).pipe(
CompiledContract.withVacantWitnesses,
CompiledContract.withCompiledFileAssets('./contracts/managed/MyNFT'),
);
const providers = await buildProviders(/* see midnight-js skill */);
const deployed = await deployContract(providers, {
compiledContract,
privateStateId: 'nftPrivateState',
initialPrivateState: {},
});
console.log('NFT Contract:', deployed.deployTxData.public.contractAddress);
// Mint an NFT
const mintResult = await deployed.callTx.mint(
{ type: 'left', value: callerPublicKey() },
1n, // tokenId
'https://my-nft.com/metadata/1.json',
);6) Shielded vs Unshielded NFTs
| Aspect | Unshielded (Public) | Shielded (Private) |
| Ownership | Public on-chain | Private, only owner knows |
| Transfers | Visible to all | Hidden, ZK-proven |
| Metadata | Public URI on-chain | Can be committed/hashed |
| Gas/user cost | DUST fees | DUST fees (1AM sponsors on preview) |
| Use case | Public art, collectibles | Confidential assets, private collectibles |
| Token ID | Visible | Can be hidden with commitments |
When to Use Shielded NFTs
- Confidential ownership: When who owns the NFT should remain private
- Private collectibles: High-value items where ownership is sensitive
- Compliance-by-design: Only reveal ownership when required
When to Use Unshielded NFTs
- Public art: Ownership is part of the value proposition
- Transparent DAOs: Governance tokens as NFTs
- Standard collectibles: Where public provenance adds value
7) Metadata Handling
Public Metadata (Unshielded)
export ledger tokenURIs: Map<Uint<128>, Opaque<"string">;
export circuit setTokenURI(
tokenId: Uint<128>,
uri: Opaque<"string">,
): [] {
tokenURIs.insert(disclose(tokenId), disclose(uri));
}Private Metadata (Shielded)
// Store only a commitment on-chain
export ledger metadataCommitments: Map<Uint<128>, Field>;
export circuit setPrivateMetadata(
tokenId: Uint<128>,
metadataHash: Field, // hash of off-chain metadata
): [] {
const commitment = persistentCommit<Uint<128>>(tokenId, freshNonce());
metadataCommitments.insert(disclose(tokenId), commitment);
}8) Common Pitfalls
| Issue | Solution |
Uint<256> token IDs | Not supported. Use Uint<128> max (circuit constraint). |
| Contract-to-contract transfers | Not yet supported. Use _unsafeTransfer with caution. |
| String concatenation for base URI | Not supported in Compact. Store full URI per token. |
tokenId overflow | Use assert(tokenId < MAX_ID, "ID overflow") before minting. |
Missing disclose() on URI | Metadata URIs are public. Use disclose() when storing. |
| Shielded transfer without proof | Owner must sign transfers. Verify with callerPublicKey(). |
9) Testing NFT Contracts
// In contracts/src/test/MyNFT.test.compact
pragma language_version >= 0.21.0;
import MyNFT;
import CompactStandardLibrary;
constructor() {
MyNFT_initialize("MyNFT", "MNFT");
}
export circuit testMint(): [] {
const tokenId = MyNFT_mint(disclose(callerPublicKey()), "uri1");
assert(tokenId == 1, "First token should be 1");
}
export circuit testTransfer(): [] {
MyNFT_transferFrom(
callerPublicKey(),
someOtherKey(),
1,
);
const newOwner = MyNFT_ownerOf(1);
assert(newOwner == someOtherKey(), "Transfer failed");
}10) Package.json Scripts
{
"scripts": {
"compact": "cd contracts && compact compile MyNFT.compact artifacts/MyNFT",
"build": "tsc && npm run compact",
"test": "cd contracts && compact compile MyNFT.test.compact artifacts/MyNFT.test"
}
}11) Useful Links
- OpenZeppelin Contracts for Compact — Library documentation
- Compact Language Guide — Smart contract language reference
- Midnight Token Functions — Native token operations
- 1AM Wallet Integration — Connect wallet for NFT interactions
- Compact Skill — Language fundamentals
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

