A comprehensive Move smart contract for NFT rental and marketplace functionality on the Sui blockchain, built using the Kiosk framework for secure NFT management.
- NFT Rental System: Rent NFTs for limited time periods without transferring ownership
- Marketplace Functionality: Buy/sell NFTs with full ownership transfer
- Time-based Expiry: Automatic rental expiration and NFT return
- Kiosk Integration: Secure NFT management using Sui's Kiosk framework
- Gas Efficient: Optimized for minimal transaction costs
- Modular Design: Clean separation of rental and marketplace logic
suiplus.move/
βββ Move.toml # Project configuration
βββ sources/
β βββ nft_rental_marketplace.move # Main smart contract
β βββ test_nft_rental_marketplace.move # Test cases
β βββ scripts/
β βββ create_listing.move # Listing creation scripts
β βββ rent_nft.move # Rental transaction scripts
β βββ buy_nft.move # Purchase transaction scripts
β βββ manage_rentals.move # Rental management scripts
βββ README.md # This file
- NFTMarketplace: Main contract managing all listings and rentals
- NFTListing: Represents an NFT available for rent/sale
- RentalAgreement: Tracks active rental agreements
- MarketplaceCap: Administrative capability for platform management
public struct NFTListing has store {
id: ID,
owner: address,
renter: Option<address>,
price: u64, // Sale price in SUI
rental_price: u64, // Daily rental price in SUI
duration: u64, // Rental duration in seconds
start_time: u64, // When rental started
status: ListingStatus,
listing_type: ListingType,
nft_id: ID,
kiosk_id: ID,
created_at: u64,
}// Initialize the marketplace
let marketplace = nft_rental_marketplace::init(ctx);nft_rental_marketplace::create_listing(
&mut marketplace,
&mut kiosk,
&kiosk_cap,
nft_id,
1000, // 1000 SUI sale price
10, // 10 SUI daily rental price
86400000, // 1 day duration in milliseconds
ListingType::Both,
&clock,
ctx
);nft_rental_marketplace::create_listing(
&mut marketplace,
&mut kiosk,
&kiosk_cap,
nft_id,
0, // No sale price
10, // 10 SUI daily rental price
86400000, // 1 day duration
ListingType::Rental,
&clock,
ctx
);nft_rental_marketplace::create_listing(
&mut marketplace,
&mut kiosk,
&kiosk_cap,
nft_id,
1000, // 1000 SUI sale price
0, // No rental price
0, // No duration
ListingType::Sale,
&clock,
ctx
);// Create payment coin
let payment = coin::mint_for_testing<SUI>(100, ctx);
// Rent the NFT
nft_rental_marketplace::rent_nft(
&mut marketplace,
listing_id,
payment,
&clock,
ctx
);// Create payment coin
let payment = coin::mint_for_testing<SUI>(1000, ctx);
// Buy the NFT
nft_rental_marketplace::buy_nft(
&mut marketplace,
listing_id,
payment,
&mut kiosk,
&kiosk_cap,
ctx
);// Check if rental has expired
nft_rental_marketplace::check_rental_expiry(
&mut marketplace,
rental_id,
&clock,
ctx
);The contract includes comprehensive test cases covering:
- NFT listing creation (rental, sale, both)
- Rental process with payment validation
- Rental expiry and automatic return
- NFT purchase with ownership transfer
- Error handling and edge cases
- Utility functions
# Run all tests
sui move test
# Run specific test
sui move test test_create_rental_listingThe contract emits events for all major operations:
NFTListed: When an NFT is listed for rent/saleNFTRented: When an NFT is rentedNFTSold: When an NFT is soldRentalExpired: When a rental expiresListingCancelled: When a listing is cancelled
- Ownership Validation: Only NFT owners can create listings
- Payment Validation: Ensures sufficient payment before transactions
- Time-based Expiry: Automatic rental expiration
- Kiosk Integration: Secure NFT management
- Reentrancy Protection: Safe against reentrancy attacks
- Access Control: Proper permission checks for all operations
The marketplace includes a configurable platform fee system:
- Default: 5% platform fee
- Configurable by marketplace administrators
- Applied to both rental and sale transactions
- Sui CLI installed
- Sui network access (testnet/mainnet)
# Build the contract
sui move build
# Deploy to testnet
sui client publish --gas-budget 100000000
# Deploy to mainnet
sui client publish --gas-budget 100000000 --network mainnetThe smart contract is designed for easy integration with TypeScript/React frontends:
- Event Listening: Monitor contract events for real-time updates
- Transaction Scripts: Use provided scripts for common operations
- State Management: Track listings, rentals, and marketplace state
- Error Handling: Implement proper error handling for all operations
// Listen for events
const unsubscribe = suiClient.subscribeEvent({
filter: { Package: marketplacePackageId },
onMessage: (event) => {
switch (event.type) {
case 'NFTListed':
// Update UI with new listing
break;
case 'NFTRented':
// Update rental status
break;
case 'RentalExpired':
// Handle rental expiry
break;
}
}
});- Bulk Operations: Batch listing, renting, and purchasing
- Advanced Pricing: Dynamic pricing based on demand
- Loyalty System: Rewards for frequent users
- Analytics: Marketplace statistics and insights
- Cross-chain: Support for other blockchains
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions and support:
- Check the documentation
- Review test cases for examples
- Open an issue on GitHub
- Join the Sui developer community
Built with β€οΈ for the Sui ecosystem