Skip to content

Samk1710/alt-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Altnode Smart Contract

Overview

Altnode is an ERC-721 NFT smart contract that enables creators to mint assets and manage subscription-based access to exclusive content. Built on Ethereum, it combines NFT ownership with a subscription model, allowing asset owners to monetize their content through time-based access controls.

Contract Details

image

  • Contract Name: Altnode
  • Symbol: AiT (Altnode Token)
  • License: GPL-3.0
  • Solidity Version: ^0.8.19
  • Contract Address: 0xcb932746885aD1eB118a57E06dbB0cfa5f779E1c
  • Network: Ethereum Mainnet

Features

Core Functionality

  • NFT Minting: Create unique asset tokens with metadata and subscription pricing
  • Subscription System: Users can purchase time-based subscriptions to access exclusive content
  • Access Control: Secure access to premium content using unique access keys
  • Owner Payments: Subscription fees are automatically transferred to asset owners
  • Subscription Management: Track active subscriptions and subscriber lists

Key Components

  1. Asset Creation: Mint NFTs with public metadata and hidden asset URIs
  2. Subscription Purchasing: Buy access to assets for specified durations
  3. Access Key Generation: Unique keys for secure content access
  4. Subscription Validation: Check if subscriptions are active
  5. Subscriber Tracking: Monitor all subscribers for each asset

Smart Contract Functions

Minting Functions

mintAsset(address to, string tokenMetadata, string assetURI, uint256 price)

  • Mints a new asset NFT
  • Sets subscription price in wei
  • Associates hidden content URI with the token
  • Access: Public

Subscription Functions

purchaseSubscription(uint256 assetId, uint256 duration)

  • Purchase subscription to an asset
  • Requires payment equal to or greater than subscription price
  • Generates unique access key
  • Access: Public (payable)

isSubscriptionValid(uint256 assetId, address subscriber)

  • Check if a subscription is currently active
  • Returns boolean value
  • Access: Public view

getActiveSubscribers(uint256 assetId)

  • Returns array of addresses with active subscriptions
  • Access: External view

Access Functions

getTokenURIByAccessKey(bytes32 accessKey, address subscriber)

  • Get public token metadata using access key
  • Requires valid subscription
  • Access: External view

getAssetURIByAccessKey(bytes32 accessKey, address subscriber)

  • Get hidden asset content using access key
  • Requires valid subscription
  • Access: External view

getAccessKeyByTokenId(uint256 assetId, address subscriber)

  • Retrieve access key for a specific asset and subscriber
  • Access: External view

Query Functions

getAllAssets()

  • Returns JSON string of all minted assets
  • Access: External view

getSubscriptions(address subscriber)

  • Returns JSON string of all active subscriptions for an address
  • Access: External view

Data Structures

Subscription Struct

struct Subscription {
    uint256 validity;    // Timestamp of subscription expiry
    bytes32 accessKey;   // Unique access key
}

Key Mappings

  • subscriptions: Maps token ID and subscriber to subscription details
  • subscriptionPrices: Maps token ID to subscription price
  • accessKeyToTokenId: Maps access key to corresponding token ID
  • tokenIdToAssetURI: Maps token ID to hidden asset URI
  • assetSubscribers: Tracks all subscribers for each asset

Events

TokenMinted

event TokenMinted(
    address indexed to,
    uint256 tokenId,
    string tokenMetadata,
    uint256 price
);

SubscriptionPurchased

event SubscriptionPurchased(
    address indexed subscriber,
    uint256 tokenId,
    uint256 validity,
    bytes32 accessKey,
    uint256 price
);

Custom Errors

  • Altnode__InvalidAssetId: Asset ID doesn't exist
  • Altnode__SubscriptionExists: Active subscription already exists
  • Altnode__InsufficientPayment: Payment below required amount
  • Altnode__InvalidAccessKey: Access key is invalid
  • Altnode__InvalidSubscription: Subscription is expired or invalid
  • Altnode__OwnerCanNotPurchase: Asset owner cannot purchase their own subscription
  • Altnode__OnlyOwner: Function restricted to contract owner

Access Control

The contract includes owner-only functionality controlled by the onlyOwner modifier. Authorized addresses include:

  • Contract deployer
  • 0xe34b40f38217f9Dc8c3534735f7f41B2cDA73A75
  • 0x6af90FF366aE23f4Bb719a56eBc910aF4C169aCE
  • 0xF23be0fbE9DEF26570278F91f3F150Af015a3ECf
  • 0xF5E93e4eEDbb1235B0FB200fd77068Cb9938eF4f

Usage Example

Minting an Asset

await altnodeContract.mintAsset(
    "0x...", // recipient address
    "ipfs://metadata-hash", // public metadata
    "ipfs://secret-content-hash", // hidden content
    ethers.utils.parseEther("0.1") // price in ETH
);

Purchasing Subscription

await altnodeContract.purchaseSubscription(
    0, // asset ID
    86400, // duration in seconds (1 day)
    { value: ethers.utils.parseEther("0.1") }
);

Accessing Content

const accessKey = await altnodeContract.getAccessKeyByTokenId(0, userAddress);
const secretContent = await altnodeContract.getAssetURIByAccessKey(
    accessKey,
    userAddress
);

Dependencies

  • OpenZeppelin ERC721 implementation
  • OpenZeppelin ERC721URIStorage extension
  • OpenZeppelin Strings utility library

Security Features

  • Prevents asset owners from purchasing their own subscriptions
  • Automatic payment forwarding to asset owners
  • Unique access key generation using keccak256 hashing
  • Subscription validity checks with timestamp-based expiration
  • Comprehensive error handling with custom error types

Development

Building

# Compile with Hardhat
npx hardhat compile

# Or with Foundry
forge build

Testing

# Run tests
npx hardhat test

# Or with Foundry
forge test

License

This project is licensed under the GPL-3.0 License - see the license identifier in the contract header.

Contact

For questions or support regarding the Altnode contract, please contact the Altnode development team.


Contract Address: 0xcb932746885aD1eB118a57E06dbB0cfa5f779E1c

Network: Ethereum Mainnet

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors