- Install Dependencies
npm install- Development Tools
- ESLint for code linting
- Prettier for code formatting
- Jest for testing
- Nodemon for hot reload
- IDE Setup
Recommended: Visual Studio Code with extensions:
- ESLint
- Prettier
- GitLens
- Thunder Client (API testing)
SmartContractAudit/
├── auditor/ # Auditor modules
│ ├── antivirus/ # Antivirus scanner
│ ├── spam/ # Spam detector
│ ├── honeypot/ # Honeypot detector
│ ├── tracer/ # Wallet tracer
│ ├── scanner/ # Deep scanner
│ └── index.js # Main auditor entry
├── contracts/ # Smart contract examples
│ ├── ethereum/ # EVM contracts
│ ├── solana/ # Solana programs
│ └── examples/ # Test contracts
├── script/ # Automation scripts
│ ├── scan.js # Scanning orchestration
│ ├── deploy.js # Deployment automation
│ ├── repair.js # Auto-repair logic
│ └── notify.js # Notification system
├── config/ # Configuration files
│ ├── chains.json # Chain configurations
│ ├── rules.json # Detection rules
│ └── notifications.json
├── .github/workflows/ # GitHub Actions
├── docs/ # Documentation
├── reports/ # Scan reports
└── tests/ # Test suite
- Create module directory:
mkdir auditor/mymodule- Create module structure:
// auditor/mymodule/index.js
class MyModule {
constructor(config) {
this.config = config;
}
async scan(target, chain) {
// Implementation
return {
target,
chain,
results: [],
score: 0
};
}
}
module.exports = MyModule;- Add tests:
// tests/mymodule.test.js
const MyModule = require('../auditor/mymodule');
describe('MyModule', () => {
test('should scan target', async () => {
const module = new MyModule({});
const result = await module.scan('0x123...', 'ethereum');
expect(result.target).toBe('0x123...');
});
});- Register module in main auditor:
// auditor/index.js
const MyModule = require('./mymodule');
class Auditor {
constructor() {
this.modules = {
mymodule: new MyModule(config.mymodule)
};
}
}- Add chain configuration:
// config/chains.json
{
"mychain": {
"name": "My Blockchain",
"rpc": "https://rpc.mychain.io",
"explorer": "https://explorer.mychain.io",
"chainId": 999,
"type": "evm",
"nativeCurrency": {
"name": "My Token",
"symbol": "MTK",
"decimals": 18
}
}
}- Create chain connector:
// auditor/connectors/mychain.js
const { ethers } = require('ethers');
class MyChainConnector {
constructor(config) {
this.provider = new ethers.providers.JsonRpcProvider(config.rpc);
}
async getContract(address) {
return await this.provider.getCode(address);
}
async getTransaction(hash) {
return await this.provider.getTransaction(hash);
}
}
module.exports = MyChainConnector;# Run all tests
npm test
# Run specific test suite
npm test -- antivirus
# Run with coverage
npm run test:coverage
# Watch mode
npm run test:watchExample test structure:
const AntivirusScanner = require('../auditor/antivirus');
describe('AntivirusScanner', () => {
let scanner;
beforeEach(() => {
scanner = new AntivirusScanner({
threshold: 70,
patterns: ['reentrancy']
});
});
describe('scanContract', () => {
test('detects reentrancy vulnerability', async () => {
const result = await scanner.scanContract(
'0xVulnerableContract',
'ethereum'
);
expect(result.vulnerabilities).toContainEqual(
expect.objectContaining({
type: 'reentrancy',
severity: 'critical'
})
);
});
test('returns clean scan for safe contract', async () => {
const result = await scanner.scanContract(
'0xSafeContract',
'ethereum'
);
expect(result.vulnerabilities).toHaveLength(0);
expect(result.riskScore).toBeLessThan(20);
});
});
});- Enable debug mode:
export DEBUG=audit:*
npm run scan -- --address 0x123... --chain ethereum- Use debugger:
// Add breakpoint
debugger;
// Run with inspector
node --inspect-brk script/scan.js --address 0x123...- VS Code launch configuration:
{
"type": "node",
"request": "launch",
"name": "Debug Scan",
"program": "${workspaceFolder}/script/scan.js",
"args": ["--address", "0x123...", "--chain", "ethereum"]
}For GitHub Actions debugging:
- Add debug step to workflow:
- name: Debug
run: |
echo "Current directory: $(pwd)"
echo "Files: $(ls -la)"
echo "Environment: ${{ toJson(env) }}"- Use act for local testing:
act -j audit-workflow# Run linter
npm run lint
# Fix auto-fixable issues
npm run lint:fix# Format code
npm run format
# Check formatting
npm run format:check- Use camelCase for variables and functions
- Use PascalCase for classes
- Use UPPER_CASE for constants
- Always use async/await over promises
- Add JSDoc comments for public APIs
- Keep functions small and focused
Example:
/**
* Scans a smart contract for vulnerabilities
* @param {string} address - Contract address
* @param {string} chain - Blockchain network
* @returns {Promise<ScanResult>} Scan results
*/
async function scanContract(address, chain) {
const scanner = new AntivirusScanner();
return await scanner.scan(address, chain);
}Implement caching for repeated scans:
const cache = new Map();
async function scanWithCache(address, chain) {
const key = `${chain}:${address}`;
if (cache.has(key)) {
return cache.get(key);
}
const result = await scan(address, chain);
cache.set(key, result);
return result;
}Use parallel processing for batch scans:
const addresses = ['0x1...', '0x2...', '0x3...'];
const results = await Promise.all(
addresses.map(addr => scanContract(addr, 'ethereum'))
);Implement rate limiting for RPC calls:
const Bottleneck = require('bottleneck');
const limiter = new Bottleneck({
maxConcurrent: 5,
minTime: 200
});
const rateLimitedScan = limiter.wrap(scanContract);- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Run linter and tests
- Submit PR with description
Follow conventional commits:
feat: add spam detection for token contracts
fix: resolve honeypot false positives
docs: update API documentation
test: add tests for wallet tracer
refactor: optimize scan performance
All PRs require:
- Passing tests
- Code review approval
- No linting errors
- Updated documentation
# Build
npm run build
# Test in staging
npm run deploy:staging
# Deploy to production
npm run deploy:productionAutomated deployment via GitHub Actions:
- Push to main branch
- Tests run automatically
- If tests pass, deploy to staging
- Manual approval for production
- Deploy to production
Issue: npm install fails
# Clear cache and retry
npm cache clean --force
rm -rf node_modules package-lock.json
npm installIssue: Tests fail locally
# Reset test environment
npm run test:clean
npm testIssue: RPC timeout in tests
// Increase timeout in test
jest.setTimeout(30000);- Review existing issues on GitHub
- Join developer Discord channel
- Check API Documentation
- Contact maintainers