# 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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
