For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 initialize exactly 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, eventForwarder is the common BaseStateMachine surface).

  • 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?