Best practices
This guide covers best practices for developing with the Guardian TypeScript SDK, including security, performance, and maintainability guidelines.
π Security Best Practices
1. Private Key Management
β Don't:
// Never hardcode private keys
const privateKey = '0x1234567890abcdef...'β Do:
// Use environment variables
const privateKey = process.env.PRIVATE_KEY
if (!privateKey) {
throw new Error('PRIVATE_KEY environment variable is required')
}
// Use secure key management services
import { getSecret } from '@aws-sdk/client-secrets-manager'
const privateKey = await getSecret('guardian-private-key')2. Input Validation
β Don't:
β Do:
3. Error Handling
β Don't:
β Do:
4. Access Control
β Don't:
β Do:
β‘ Performance Best Practices
1. Client Reuse
β Don't:
β Do:
2. Batch Operations
β Don't:
β Do:
3. Gas Optimization
β Don't:
β Do:
4. Caching
β Don't:
β Do:
ποΈ Code Organization
1. Modular Architecture
β Don't:
β Do:
2. Type Safety
β Don't:
β Do:
3. Configuration Management
β Don't:
β Do:
π§ͺ Testing Best Practices
1. Test Structure
β Don't:
β Do:
2. Mocking
β Don't:
β Do:
3. Integration Testing
β Don't:
β Do:
π Monitoring & Logging
1. Structured Logging
β Don't:
β Do:
2. Metrics Collection
β Don't:
β Do:
π Deployment Best Practices
1. Environment Separation
β Don't:
β Do:
2. Health Checks
β Don't:
β Do:
3. Upgradeable contracts: call initialize in the deployment transaction
Account and other initializerβbased contracts must have storage wired once on the instance users interact with (the proxy or minimal proxy), in the correct order for your inheritance chain.
Prefer a factory that performs create + initialize atomically so a failed init never leaves an uninitialized live address. The Solidity reference is CopyBlox (contracts/examples/applications/CopyBlox/CopyBlox.sol): clone via EIPβ1167, then initialize(address,address,address,uint256,address); revert if the call fails.
If you deploy proxies manually:
Run
initializeexactly once on the proxy, not only on the implementation (unless your stack explicitly uses a different OZ patternβdocument it).Align parameter order with your concrete contract (owner, broadcaster, recovery, timelock seconds,
eventForwarderis the commonBaseStateMachinesurface).After deploy, verify critical reads (
owner, recovery, timelock) before moving liquidity or production traffic.
π Documentation Best Practices
1. Code Documentation
β Don't:
β Do:
2. README Documentation
β Don't:
β Do:
API Reference
See API Documentation for complete reference.
Contributing
See Contributing Guide for development guidelines.
Last updated
Was this helpful?