This guide explains how to use the mainnet interaction script while minimizing gas consumption.
Use read-only calls whenever possible - they're FREE and don't consume gas!
| Operation | Gas Cost | Type |
|---|---|---|
| Get institution count | FREE | Read-only |
| Get verified count | FREE | Read-only |
| Get institution details | FREE | Read-only |
| Get total issued | FREE | Read-only |
| Get total revoked | FREE | Read-only |
| Get total active | FREE | Read-only |
| Get credential details | FREE | Read-only |
| Verify credential by hash | FREE | Read-only |
| Register institution | ~0.01-0.05 STX | State-changing |
| Issue credential | ~0.01-0.05 STX | State-changing |
| Verify credential | ~0.01-0.05 STX | State-changing |
| Revoke credential | ~0.01-0.05 STX | State-changing |
npm run mainnet-interactThis will:
- Get institution count
- Get verified institutions count
- Get total credentials issued
- Get total credentials revoked
- Get total active credentials
- Get first institution details
- Cost: 0 STX ✅
Edit scripts/mainnet-interact.js and uncomment the operations you want:
// Uncomment the operations you need:
// Register institution
await registerInstitution(
'University of Example',
'Country',
'REG-001',
'https://metadata.example.com/uni'
);
// Issue credential
await issueCredential(
'SP2STUDENT_ADDRESS',
0,
'Bachelor of Science',
'a'.repeat(64),
'https://metadata.example.com/credential'
);
// Verify credential
await verifyCredential(0);
// Revoke credential
await revokeCredential(0, 'Fraudulent credential');Then run:
npm run mainnet-interactInstead of multiple transactions, combine operations when possible.
Always check data with read-only calls before making state changes:
// FREE - Check if credential exists
const credential = await getCredential(0);
// Only if needed - Issue credential (COSTS GAS)
if (!credential) {
await issueCredential(...);
}Check current gas prices before deploying:
- Visit: https://explorer.stacks.co/
- Look at recent transactions
- Adjust timing if prices are high
Always test on testnet before mainnet:
# Edit .env
STACKS_NETWORK=testnet
# Run script
npm run mainnet-interact// Get total institutions
await getInstitutionCount();
// Get verified institutions
await getVerifiedCount();
// Get institution by ID
await getInstitution(0);
// Get total credentials issued
await getTotalIssued();
// Get total credentials revoked
await getTotalRevoked();
// Get total active credentials
await getTotalActive();
// Get credential by ID
await getCredential(0);
// Verify credential by hash
await verifyCredentialHash('a'.repeat(64));// Register institution
await registerInstitution(
'University Name',
'Country',
'REG-NUMBER',
'https://metadata-uri'
);
// Issue credential
await issueCredential(
'SP2STUDENT_ADDRESS',
institutionId,
'Credential Type',
'credential-hash',
'https://metadata-uri'
);
// Verify credential
await verifyCredential(credentialId);
// Revoke credential
await revokeCredential(credentialId, 'Reason');After running state-changing operations:
- Get transaction ID from script output
- Visit Stacks Explorer: https://explorer.stacks.co/
- Search transaction ID
- Monitor confirmation (usually 10-30 minutes)
-
Test on testnet first
STACKS_NETWORK=testnet npm run mainnet-interact
-
Verify contract addresses
cat deployments/deployment.json
-
Check gas prices
- Visit Stacks Explorer
- Look at recent transaction costs
- Start with read-only calls (FREE)
- Only do state-changing operations when necessary
- Monitor transaction confirmations
- Keep transaction IDs for records
| Operation | Estimated Cost |
|---|---|
| Register institution | 0.01-0.05 STX |
| Issue credential | 0.01-0.05 STX |
| Verify credential | 0.01-0.05 STX |
| Revoke credential | 0.01-0.05 STX |
| Total for all 4 | 0.04-0.20 STX |
- Use read-only calls (FREE)
- Batch operations when possible
- Deploy during low-gas periods
- Test on testnet first
npm run mainnet-interactCheck current state without spending gas.
Review the data and decide what changes are needed.
Edit script to uncomment needed operations.
npm run mainnet-interactCheck transaction on Stacks Explorer.
- Check your STX balance
- Add more STX to your account
- Wait 30+ minutes
- Check network status
- Try again with higher gas
- Verify contract addresses in
deployments/deployment.json - Ensure you're on correct network
- ✅ Use read-only calls for monitoring (FREE)
- ✅ Only use state-changing operations when necessary
- ✅ Test on testnet first
- ✅ Monitor gas prices
- ✅ Keep transaction records
This approach minimizes gas costs while keeping your contracts fully functional on mainnet!