This smart contract provides functionality for pinning IPFS content through a precompile interface on the UOMI network. It allows both agent-based pinning and duration-based file pinning with payment functionality.
- Pin agent-specific content with NFT ID association
- Pin files with customizable duration (minimum 24 hours)
- Pay-per-block pricing model for file pinning
- Secure withdrawal mechanism for contract owner
- Node.js (14.x or later)
- Hardhat
- An Ethereum wallet with UOMI tokens for testing
- Clone the repository:
git clone <your-repo-url>
cd <your-repo-name>
- Install dependencies:
npm install
- Create a
.env
file in the root directory and add your configuration:
PRIVATE_KEY=your_private_key
UOMI_RPC_URL=your_uomi_network_rpc_url
PRECOMPILE_ADDRESS_IPFS
: The address of the IPFS precompile contract (0x0000000000000000000000000000000000000101)pricePerBlock
: 0.01 UOMI per block (10000000000000000 wei)
- Initializes the contract with the specified owner address
- Parameters:
_owner
: Address that will be able to withdraw funds from the contract
- Pins content associated with an agent's NFT
- Parameters:
_cid
: IPFS CID in bytes format_nftId
: Associated NFT ID
- Pins a file for a specified duration
- Requires payment based on duration
- Parameters:
_cid
: IPFS CID in bytes format_durationInBlocks
: How long to pin the file (minimum 28800 blocks ≈ 24 hours)
- Requirements:
- Duration must be >= 28800 blocks
- Payment must be >= (durationInBlocks * pricePerBlock)
- Allows the owner to withdraw accumulated funds
- Can only be called by the contract owner
- Configure your network in
hardhat.config.js
:
require("@nomiclabs/hardhat-waffle");
require('dotenv').config();
module.exports = {
solidity: "0.8.28",
networks: {
uomi: {
url: process.env.UOMI_RPC_URL,
accounts: [process.env.PRIVATE_KEY]
}
}
};
- Deploy the contract:
npx hardhat run scripts/deploy.js --network uomi
Example script for pinning a file:
const { ethers } = require("hardhat");
async function main() {
const contract = await ethers.getContractAt("IPFSStorage", "YOUR_CONTRACT_ADDRESS");
// Example: Pin a file for 24 hours (28800 blocks)
const cid = ethers.utils.toUtf8Bytes("QmYourIPFSHash");
const duration = 28800;
const price = ethers.utils.parseEther("0.01").mul(duration);
await contract.pinFile(cid, duration, { value: price });
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
Run the test suite:
npx hardhat test
- The contract handles user funds, so thorough testing is essential
- Only the owner can withdraw funds
- Minimum duration prevents spam transactions
- Payment validation ensures proper compensation for pinning services
UNLICENSED
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request