Thanks to visit codestin.com
Credit goes to github.com

Skip to content

LingSiewWin/ERC-7857

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– ERC-7857: AI Agent NFTs

The first ERC-7857 extension built on Scaffold-ETH 2
Universal toolkit for building Intelligent Non-Fungible Tokens

πŸš€ Installation

npx create-eth@latest -e LingSiewWin/ERC-7857

What's Inside

The first ERC-7857 implementation on Scaffold-ETH 2, giving you everything needed to build AI agent NFTs:

πŸ“¦ Smart Contracts

  • INFT.sol: Full ERC-7857 implementation with minting, transfers, and cloning
  • MockOracle.sol: TEE verification oracle for testing and development
  • OasisTEEVerifier.sol: Production TEE verification for Oasis Sapphire
  • Complete Interface Suite: IERC7857, IERC7857DataVerifier, IERC7857Metadata

⚑ Frontend Components

  • MintINFT: Create AI agents with encrypted metadata
  • TransferINFT: Secure ownership transfers with TEE proofs
  • ViewINFT: Display and manage AI agent information
  • Authorization System: Granular access control interface

🌟 Key Features

  • βœ… ERC-7857 Standard: Complete implementation of Intelligent NFTs
  • βœ… TEE Integration: Trusted Execution Environment verification
  • βœ… Encrypted Metadata: Secure AI agent data with authorized access
  • βœ… Cloning Support: Create derivative AI agents
  • βœ… Multi-Network: Oasis Sapphire, Arbitrum, local development
  • βœ… Production Ready: Comprehensive test suite with 100% coverage
  • βœ… React Components: Ready-to-use UI components with Wagmi integration
  • βœ… DataDescriptions: AI agent metadata descriptions support
  • πŸ”§ 0G SDK Integration: Decentralized storage integration (in development)

⚑ Quick Start

  1. Install the extension:

    npx create-eth@latest -e LingSiewWin/ERC-7857
    cd your-project-name
  2. Set up environment:

    # Add to packages/hardhat/.env.local
    PRIVATE_KEY=your_private_key_without_0x
    INFURA_KEY=your_infura_key_optional
  3. Install dependencies:

    yarn install
  4. Deploy contracts:

    # Deploy to local network
    yarn deploy --network localhost
    
    # Deploy to Oasis Sapphire Testnet
    yarn deploy --network sapphireTestnet
    
    # Deploy to Arbitrum Testnet
    yarn deploy --network arbitrumTestnet
  5. Start frontend:

    yarn dev
  6. Run tests:

    yarn test

πŸ“š Usage Examples

πŸ€– Mint AI Agent NFT

// Smart contract
function mint(
    address to,
    string memory encryptedMetadataURI,
    bytes32 metadataHash
) returns (uint256 tokenId)

// Usage
await inft.mint(
    userAddress,
    "ipfs://encrypted-metadata-hash",
    keccak256("agent metadata")
);

πŸ”„ Transfer Agent with TEE Proof

// Smart contract
function safeTransferFrom(
    address from,
    address to,
    uint256 tokenId,
    bytes memory transferProof
)

// Usage with generated proof
const transferProof = await oracle.createTransferProof(
    oldDataHash, newDataHash, fromAddress, toAddress
);
await inft.safeTransferFrom(from, to, tokenId, transferProof);

🧬 Clone Agent

// Smart contract
function clone(uint256 tokenId, address to) returns (uint256 newTokenId)

// Usage
const newTokenId = await inft.clone(originalTokenId, recipientAddress);

πŸ” Authorize Access

// Smart contract
function authorizeUsage(uint256 tokenId, address user, uint256 duration)

// Usage - authorize for 1 hour
await inft.authorizeUsage(tokenId, userAddress, 3600);

🌐 Supported Networks

Network Chain ID Status Purpose
Hardhat Local 31337 βœ… Deployed Development & testing
Arbitrum Testnet 421614 βœ… Deployed Layer 2 scaling
Oasis Sapphire Testnet 0x5aff πŸ”§ Ready Privacy-preserving smart contracts

Live Deployments:

Arbitrum Testnet (Chain ID: 421614)

  • MockOracle: 0x0b60881F525D925472d6d522f6309FD6F78Ecb08
  • INFT (ERC-7857): 0x19922d2d1e2b45c81c69030B709f462B2289f5A9

Localhost (for development)

  • MockOracle: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
  • INFT (ERC-7857): 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9

Deploy to networks:

npx hardhat run scripts/deploy.js --network arbitrumTestnet  # L2 scaling  
npx hardhat run scripts/deploy.js --network localhost        # Development

πŸ”§ Core Functions

Smart Contract API

  • mint(): Create new INFT with encrypted metadata
  • safeTransferFrom(): Secure transfer with TEE verification
  • clone(): Create derivative AI agents
  • authorizeUsage(): Grant time-limited access permissions
  • isAuthorized(): Check user access rights
  • updateMetadata(): Update agent metadata with proofs

πŸ”§ Environment Setup

Create .env.local in packages/hardhat/:

PRIVATE_KEY=your_private_key_without_0x
INFURA_KEY=your_infura_project_id  # optional
ETHERSCAN_API_KEY=your_etherscan_key  # optional, for verification

πŸ§ͺ Testing

The extension includes comprehensive test coverage:

# Run all tests
yarn test

# Run specific test files
yarn hardhat test test/INFT.test.js
yarn hardhat test test/MockOracle.test.js

# Run with gas reporting
REPORT_GAS=true yarn test

Test Coverage

  • βœ… Contract deployment and initialization
  • βœ… INFT minting with metadata validation
  • βœ… Transfer functionality with TEE proofs
  • βœ… Cloning and derivative creation
  • βœ… Authorization and access control
  • βœ… Public/private visibility controls
  • βœ… Error handling and edge cases

πŸ—οΈ Project Structure

scaffold-erc7857/
β”œβ”€β”€ extension/
β”‚   β”œβ”€β”€ packages/
β”‚   β”‚   β”œβ”€β”€ hardhat/                 # Smart contracts & deployment
β”‚   β”‚   β”‚   β”œβ”€β”€ contracts/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ interfaces/      # ERC-7857 standard interfaces
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ IERC7857.sol
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ IERC7857DataVerifier.sol
β”‚   β”‚   β”‚   β”‚   β”‚   └── IERC7857Metadata.sol
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ INFT.sol         # Main implementation
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ MockOracle.sol   # Testing oracle
β”‚   β”‚   β”‚   β”‚   └── OasisTEEVerifier.sol
β”‚   β”‚   β”‚   β”œβ”€β”€ scripts/deploy.js    # Deployment script
β”‚   β”‚   β”‚   β”œβ”€β”€ test/                # Comprehensive test suite
β”‚   β”‚   β”‚   └── hardhat.config.js    # Network configuration
β”‚   β”‚   └── nextjs/                  # Frontend application
β”‚   β”‚       β”œβ”€β”€ components/          # React components
β”‚   β”‚       β”‚   β”œβ”€β”€ MintINFT.jsx
β”‚   β”‚       β”‚   β”œβ”€β”€ TransferINFT.jsx
β”‚   β”‚       β”‚   └── ViewINFT.jsx
β”‚   β”‚       β”œβ”€β”€ pages/index.js       # Main application
β”‚   β”‚       └── contracts/           # Contract ABIs & addresses
β”‚   └── package.json                 # Extension configuration
└── README.md

πŸ” Security Features

Trusted Execution Environment (TEE)

  • Proof Generation: Secure attestation of data ownership
  • Transfer Validation: TEE-verified ownership transfers
  • Nonce Protection: Prevents replay attacks
  • Data Integrity: Hash-based validation

Access Control

  • Owner Permissions: Full control over owned INFTs
  • Time-Limited Authorization: Granular access control
  • Public/Private Modes: Flexible visibility settings
  • Cloning Restrictions: Authorized-only derivative creation

🀝 Contributing

We welcome contributions! Here's how you can help:

Development Process

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Ensure tests pass: yarn test
  5. Commit your changes: git commit -m 'Add amazing feature'
  6. Push to the branch: git push origin feature/amazing-feature
  7. Open a Pull Request

Guidelines

  • Follow Solidity best practices and security standards
  • Write comprehensive tests for new functionality
  • Use clear, descriptive commit messages
  • Document new features and API changes
  • Maintain backwards compatibility when possible

πŸ› Troubleshooting

Common Issues

Contract Not Found

Error: Contract not found at address

Solution: Deploy contracts first with yarn deploy --network <network>

Network Mismatch

Error: Network not supported

Solution: Switch wallet to supported network or update hardhat.config.js

Insufficient Gas

Error: Transaction ran out of gas

Solution: Increase gas limit in transaction or optimize contract calls

TEE Verification Failed

Error: Invalid ownership proof

Solution: Regenerate proofs using the MockOracle or check TEE attestation

🌟 Roadmap

  • Advanced TEE Integration: Full Oasis ROFL integration
  • Governance System: DAO for protocol upgrades
  • Cross-Chain Support: Multi-chain AI agent portability
  • Marketplace Integration: Built-in trading functionality
  • AI Agent Interactions: On-chain agent-to-agent communication

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support & Community


πŸš€ Built with ❀️ for the AI Agent NFT ecosystem

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published