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

  1. Installation

  2. Quick Start

  3. Authentication & Client Setup

  4. AuditorService Methods

  5. Request Models & Parameters

  6. Response Models

  7. Error Handling

  8. Best Practices

  9. Complete Examples


Installation

pip install chaingpt

Requirements:

  • Python 3.8+

  • Valid ChainGPT API key


Quick Start


Authentication & Client Setup

Environment Setup:


AuditorService Methods

1. audit_contract() - Complete Audit Response

Returns 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

Streams 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

Retrieves 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:

Field
Type
Required
Description

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:

  1. Reentrancy vulnerabilities

  2. Integer overflow/underflow

  3. Access control issues

  4. Gas optimization opportunities

  5. 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?