This guide explains how to use the InteractPoco.s.sol script to interact with a deployed PoCo Diamond proxy.
The InteractPoco.s.sol script provides a comprehensive interface for interacting with the PoCo Diamond proxy, demonstrating various functionalities including:
- Protocol Information: View basic protocol details, statistics, and configuration
- Diamond Structure: Inspect diamond facets and function selectors
- Token Operations: Deposit/withdraw RLC tokens to/from escrow
- Category Management: Create and view categories
- Admin Functions: Configure protocol parameters (owner only)
- User Functions: Check balances, allowances, and view categories
- Deployed PoCo Diamond: You need a deployed PoCo Diamond proxy
- RLC Token: Optional but recommended for token interaction demos
- Environment Variables: Set required environment variables
- Private Key: Required for transaction-based interactions
Create a .env file with the following variables:
# Required
DIAMOND_ADDRESS=0x... # Address of the deployed PoCo Diamond proxy
RPC_URL=http://127.0.0.1:8545 # RPC URL for the network
# Optional
RLC_TOKEN_ADDRESS=0x... # Address of the RLC token contract
USER_ADDRESS=0x... # Address of a user to query (defaults to a sample address)
OWNER_ADDRESS=0x... # Address of the contract owner (defaults to msg.sender)
PRIVATE_KEY=0x... # Private key for broadcasting transactions (optional for read-only)Run the script without a private key to view protocol information:
# Using make
make interact-poco-read-only
# Using forge directly
forge script script/InteractPoco.s.sol:InteractPoco --rpc-url $RPC_URL --broadcast -vvThis will show:
- Protocol information (name, symbol, decimals, total supply)
- Diamond structure (facets and functions)
- Category information
- User balances (read-only)
Set a private key to enable transaction-based interactions:
# Using make
make interact-poco-local
# Using forge directly
forge script script/InteractPoco.s.sol:InteractPoco --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast -vvThis will perform:
- All read-only operations
- RLC token deposits/withdrawals (if RLC token is configured)
- Category creation (if caller is owner)
- Other admin functions (if caller is owner)
The script also provides individual utility functions that can be called directly:
# Deposit 10 RLC (10 * 10^9 wei)
forge script script/InteractPoco.s.sol:InteractPoco --sig "depositRLC(uint256)" 10000000000 --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast -vv# Withdraw 5 RLC (5 * 10^9 wei)
forge script script/InteractPoco.s.sol:InteractPoco --sig "withdrawRLC(uint256)" 5000000000 --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast -vv# Create a new category
forge script script/InteractPoco.s.sol:InteractPoco --sig "createCategory(string,string,uint256)" "AI Computing" "AI and machine learning workloads" 300 --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast -vv# View detailed protocol statistics
forge script script/InteractPoco.s.sol:InteractPoco --sig "viewProtocolStats()" --rpc-url $RPC_URL --broadcast -vv# Check balance for a specific user
forge script script/InteractPoco.s.sol:InteractPoco --sig "checkUserBalance(address)" 0x1234567890123456789012345678901234567890 --rpc-url $RPC_URL --broadcast -vv# List all categories with details
forge script script/InteractPoco.s.sol:InteractPoco --sig "listAllCategories()" --rpc-url $RPC_URL --broadcast -vv# Show complete diamond structure
forge script script/InteractPoco.s.sol:InteractPoco --sig "analyzeDiamondStructure()" --rpc-url $RPC_URL --broadcast -vvThe script includes comprehensive error handling:
- Try-catch blocks for all external calls
- Graceful failure with informative error messages
- Continues execution even if some operations fail
- Validates required environment variables
- Checks balances before attempting operations
- Requires sufficient token balances for demos
- Works with or without private keys
- Automatically detects owner status
- Adapts behavior based on available configuration
When you run the script, you'll see output like:
=== PoCo Diamond Interaction Script ===
Diamond Address: 0x1234...
RLC Token Address: 0x5678...
User Address: 0x9abc...
Owner Address: 0xdef0...
Has Private Key: true
=== Protocol Information ===
Name: iEx.ec Network Token
Symbol: RLC
Decimals: 9
Total Supply: 87000000000000000
Owner: 0xdef0...
RLC Token Address: 0x5678...
Category Count: 1
=== Diamond Information ===
Number of Facets: 8
Facet 0: 0x1111...
Function Count: 4
Selector 0: 0x8da5cb5b
Selector 1: 0xf2fde38b
... and 2 more
=== Token Interactions ===
RLC Token Balance: 100000000000
Approving 10000000000 RLC tokens for deposit...
Approval successful
Depositing 10000000000 RLC tokens...
Deposit successful
New escrow balance: 10000000000
-
"DIAMOND_ADDRESS must be set"
- Ensure you've set the
DIAMOND_ADDRESSenvironment variable
- Ensure you've set the
-
"Insufficient RLC balance"
- Check that your account has enough RLC tokens for the demo amounts
- Modify the demo amounts in the script if needed
-
"Only owner can call this function"
- Admin functions are restricted to the contract owner
- Verify your account is the owner or use a different account
-
"Failed to retrieve..."
- Check that the diamond proxy is deployed and accessible
- Verify the RPC URL is correct and the network is reachable
- Use verbose output: Add
-vvor-vvvto see more detailed logs - Check network: Ensure you're connected to the correct network
- Verify addresses: Double-check all addresses in your
.envfile - Test read-only first: Start with read-only operations to verify basic connectivity
You can customize the script by:
- Modifying demo amounts: Change
DEMO_DEPOSIT_AMOUNTandDEMO_WITHDRAW_AMOUNTconstants - Adding new functions: Extend the script with additional utility functions
- Adjusting output: Modify console.log statements to show different information
- Error handling: Customize error messages or recovery logic
- Never commit private keys: Keep your
.envfile secure and never commit it to version control - Use testnets: Test on testnets before using mainnet
- Verify addresses: Always double-check contract addresses before interacting
- Check permissions: Ensure you have appropriate permissions for the operations you're trying to perform
The script is integrated with the project's Makefile for easy execution:
make interact-poco-local: Full interaction with local deploymentmake interact-poco-read-only: Read-only interaction without private keymake deploy-poco-local: Deploy PoCo Diamond to local network first
This provides a complete workflow for deploying and interacting with the PoCo Diamond proxy.