> For the complete documentation index, see [llms.txt](https://docs.chaingpt.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chaingpt.org/dev-docs-b2b-saas-api-and-sdk/chaingpt-claude-skill-and-plugin/products/smart-contract-generator.md).

# Smart Contract Generator

## Smart Contract Generator

Generate production-ready Solidity smart contracts from natural language descriptions. Powered by the same streaming endpoint as the LLM chatbot, using a specialized model fine-tuned for smart contract generation.

### Key Facts

|              |                                                    |
| ------------ | -------------------------------------------------- |
| **Endpoint** | `POST /chat/stream`                                |
| **Model**    | `smart_contract_generator`                         |
| **Cost**     | 1 credit per request (2 with chat history enabled) |
| **SDK**      | `@chaingpt/smartcontractgenerator`                 |
| **Output**   | Solidity source code                               |

### Parameters

| Parameter     | Type   | Required | Description                                                                                                        |
| ------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------ |
| `model`       | string | Yes      | Must be `"smart_contract_generator"`                                                                               |
| `question`    | string | Yes      | Natural language description of the contract you want                                                              |
| `chatHistory` | string | No       | `"on"` or `"off"` (string, not boolean). Enables iterative refinement. Doubles cost to 2 credits. Default: `"off"` |
| `sdkUniqueId` | string | No       | Unique session identifier for maintaining conversation context                                                     |

### Quick Start -- JavaScript

```bash
npm install @chaingpt/smartcontractgenerator
```

```javascript
import { SmartContractGenerator } from "@chaingpt/smartcontractgenerator";

const client = new SmartContractGenerator({
  apiKey: process.env.CHAINGPT_API_KEY,
});

const response = await client.createChatMessage({
  model: "smart_contract_generator",
  question:
    "Create an ERC-721 NFT contract with a max supply of 10,000, " +
    "0.05 ETH mint price, and an owner-only withdraw function. " +
    "Include a merkle proof whitelist for presale.",
  chatHistory: "off",
});

console.log(response.data.bot);
```

#### Iterative Refinement with Chat History

```javascript
// First request: generate the base contract
const base = await client.createChatMessage({
  model: "smart_contract_generator",
  question: "Create a simple ERC-20 token with 1 billion supply and 2% burn on transfer",
  chatHistory: "on",
  sdkUniqueId: "session-contract-001",
});

console.log(base.data.bot);

// Follow-up: modify the contract
const revised = await client.createChatMessage({
  model: "smart_contract_generator",
  question: "Add a 1% reflection mechanism and an anti-whale max transaction limit of 1%",
  chatHistory: "on",
  sdkUniqueId: "session-contract-001",
});

console.log(revised.data.bot);
```

### Tips

* Be specific in your descriptions -- include token standards (ERC-20, ERC-721, ERC-1155), access control requirements, and any special mechanisms.
* Use chat history for iterative refinement: generate a base contract, then request modifications in follow-up messages.
* Always pipe the generated output into the Smart Contract Auditor before deploying. The Generator + Auditor combo is the most natural pairing in the suite.
* For offline or self-hosted Solidity generation, see the Solidity LLM.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.chaingpt.org/dev-docs-b2b-saas-api-and-sdk/chaingpt-claude-skill-and-plugin/products/smart-contract-generator.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
