Python
CGPT SDK Docs
ChainGPT Smart Contract Auditor Python SDK Documentation
The ChainGPT Smart Contract Auditor provides automated security vulnerability analysis for smart contracts. It offers comprehensive audit reports with support for both immediate and streaming responses, plus session-based history tracking.
Table of Contents
Installation
Quick Start
Authentication & Client Setup
AuditorService Methods
Request Models & Parameters
Response Models
Error Handling
Best Practices
Complete Examples
Installation
pip install chaingptRequirements:
Python 3.8+
Valid ChainGPT API key
Quick Start
Authentication & Client Setup
Environment Setup:
AuditorService Methods
1. audit_contract() - Complete Audit Response
audit_contract() - Complete Audit ResponseReturns the full audit report in a single response.
When to use:
You want the complete audit report at once
Working with shorter contracts
Building batch processing systems
Example:
2. stream_audit() - Streaming Audit Response
stream_audit() - Streaming Audit ResponseStreams the audit report progressively as it's generated.
When to use:
Large contracts with lengthy audit reports
Real-time UI updates
Progressive result display
Example:
3. get_audit_history() - Session History
get_audit_history() - Session HistoryRetrieves past audit conversations for a session.
Parameters:
limit: Max entries to return (default: 10)offset: Pagination offset (default: 0)sort_by: Sort field (default: "createdAt")sort_order: "asc" or "desc" (default: "desc")sdk_unique_id: Required for session-specific history
Example:
Request Models & Parameters
SmartContractAuditRequestModel
Field Details:
model
Literal
No
Always "smart_contract_auditor" (auto-set)
question
str
Yes
Contract code + audit instructions
chatHistory
enum
No
ON or OFF (default: OFF)
sdkUniqueId
str
Conditional
Required if chatHistory=ON, 1-100 chars
Crafting Effective Questions:
Focus on:
Reentrancy vulnerabilities
Integer overflow/underflow
Access control issues
Gas optimization opportunities
Best practice compliance """
Chat History & Sessions
Without History (Stateless):
With History (Session-based):
Response Models
LLMResponseModel (for audit results)
GetChatHistoryResponseModel (for history)
Error Handling
Exception Hierarchy
Comprehensive Error Handling
Best Practices
1. Resource Management
2. Session Management
3. Contract Preparation
4. Streaming Best Practices
Complete Examples
Example 1: Basic Contract Audit
Example 2: Session-Based Multi-Contract Audit
Example 3: Production-Ready Audit Service
This documentation provides a comprehensive guide for developers to effectively use the ChainGPT Smart Contract Auditor SDK with practical examples, best practices, and robust error handling patterns.
Last updated
Was this helpful?