Socket
Book a DemoInstallSign in
Socket

@chaingpt/smartcontractauditor

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chaingpt/smartcontractauditor

SDK for Smart Contract Auditing

0.0.2
latest
npmnpm
Version published
Weekly downloads
5
66.67%
Maintainers
3
Weekly downloads
 
Created
Source

ChainGPT Smart Contract Auditor SDK

This library provides convenient access to the ChainGPT Smart Contract Auditor REST API from TypeScript or JavaScript.

Installation

npm install --save @chaingpt/smartcontractauditor
# or
yarn add smartcontractauditor

Usage

Audit a smart contract as a stream:

import { SmartContractAuditor } from "@chaingpt/smartcontractauditor";

const smartcontractauditor = new SmartContractAuditor({
  apiKey: 'Your ChainGPT API Key',
});

async function main() {
  const stream = await smartcontractauditor.auditSmartContractStream({
    question: 
    `Audit the following contract:
    pragma solidity ^0.8.0;
    contract Counter {
      uint256 private count; // This variable will hold the count
      constructor() {
        count = 0; // Initialize count to 0
      }
      function increment() public {
        count += 1;
        emit CountChanged(count); // Emit an event whenever the count changes
      }
    }`
    ,
    chatHistory: "on"
  });
  stream.on('data', (chunk: any) => console.log(chunk.toString()));
  stream.on('end', () => console.log("Stream ended"));
}

main();

Audit a smart contract as a blob:

import { SmartContractAuditor } from "@chaingpt/smartcontractauditor";

const smartcontractauditor = new SmartContractAuditor({
  apiKey: 'Your ChainGPT API Key',
});

async function main() {
  const response = await smartcontractauditor.auditSmartContractBlob({
    question: 
      `Audit the following contract:
      pragma solidity ^0.8.0;
      contract Counter {
        uint256 private count; // This variable will hold the count
        constructor() {
          count = 0; // Initialize count to 0
        }
        function increment() public {
          count += 1;
          emit CountChanged(count); // Emit an event whenever the count changes
        }
      }`,
    chatHistory: "off"
  })
  console.log(response.data.bot);
}

main();

Retrieve smart contract auditing history:

import { SmartContractAuditor } from "@chaingpt/smartcontractauditor";

const smartcontractauditor = new SmartContractAuditor({
  apiKey: 'Your ChainGPT API Key',
});

async function main() {
  const response = await smartcontractauditor.getChatHistory({
    limit: 10,
    offset: 0,
    sortBy: "createdAt",
    sortOrder: "DESC"
  })
  console.log(response.data.rows);
}

main();

Handling errors

When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), and error of the class SmartContractAuditorError will be thrown:

import { Errors } from '@chaingpt/smartcontractauditor';

async function main() {
  try {
    const stream = await smartcontractauditor.auditSmartContractStream({
      question: 
      `Audit the following contract:
      pragma solidity ^0.8.0;
      contract Counter {
        uint256 private count; // This variable will hold the count
        constructor() {
          count = 0; // Initialize count to 0
        }
        function increment() public {
          count += 1;
          emit CountChanged(count); // Emit an event whenever the count changes
        }
      }`
      ,
      chatHistory: "on"
    });
    stream.on('data', (chunk: any) => console.log(chunk.toString()));
    stream.on('end', () => console.log("Stream ended"));
  } catch(error) {
    if(error instanceof Errors.SmartContractAuditorError) {
      console.log(error.message)
    }
  }
}

main();

Manage Chat History :

  • If you want to save the user-specific history, you must pass the sdkUniqueId parameter along with the chat history. This applies to both streaming and blob cases.
import { SmartContractAuditor } from "@chaingpt/smartcontractauditor";

const smartcontractauditor = new SmartContractAuditor({
  apiKey: 'Your ChainGPT API Key',
});
const  uniqueUUid="907208eb-0929-42c3-a372-c21934fbf44f"   // your unique uuid of your specific user
async function main() {
  const response = await smartcontractauditor.auditSmartContractBlob({
    question: 
      `Audit the following contract:
      pragma solidity ^0.8.0;
      contract Counter {
        uint256 private count; // This variable will hold the count
        constructor() {
          count = 0; // Initialize count to 0
        }
        function increment() public {
          count += 1;
          emit CountChanged(count); // Emit an event whenever the count changes
        }
      }`,
    chatHistory: "on",
    sdkUniqueId:uniqueUUid
  })
  console.log(response.data.bot);
}

main();


Keywords

ai

FAQs

Package last updated on 24 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.