> 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/solidity-llm.md).

# Solidity LLM

## Solidity LLM

An open-source 2-billion-parameter language model fine-tuned specifically for Solidity smart contract generation. Hosted on HuggingFace, MIT-licensed, and completely free to run on your own hardware.

### Key Facts

|                              |                                                              |
| ---------------------------- | ------------------------------------------------------------ |
| **Model**                    | `Chain-GPT/Solidity-LLM`                                     |
| **Parameters**               | 2B                                                           |
| **License**                  | MIT                                                          |
| **Cost**                     | Free (self-hosted)                                           |
| **Platform**                 | [HuggingFace](https://huggingface.co/Chain-GPT/Solidity-LLM) |
| **Compilation Success Rate** | 83%                                                          |

### When to Use This vs. the Smart Contract Generator

|                | Solidity LLM                                           | Smart Contract Generator            |
| -------------- | ------------------------------------------------------ | ----------------------------------- |
| **Cost**       | Free                                                   | 1 credit per request                |
| **Hosting**    | Self-hosted (you need a GPU)                           | Cloud API                           |
| **Model size** | 2B parameters                                          | Larger, more capable model          |
| **Quality**    | Good (83% compilation rate)                            | Higher quality, production-tuned    |
| **Offline**    | Yes                                                    | No                                  |
| **Best for**   | Experimentation, CI pipelines, air-gapped environments | Production contracts, complex logic |

Use the Solidity LLM when you need offline generation, want zero API costs, or are integrating into CI/CD pipelines. Use the Smart Contract Generator when you need higher-quality output for production contracts.

### Quick Start -- Python

#### Install Dependencies

```bash
pip install transformers torch
```

#### Generate a Smart Contract

```python
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "Chain-GPT/Solidity-LLM"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

prompt = "Create a Solidity smart contract for an ERC-20 token with a 2% burn mechanism"

inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(
    **inputs,
    max_new_tokens=1024,
    temperature=0.7,
    do_sample=True,
)

generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_code)
```

#### With GPU Acceleration

```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "Chain-GPT/Solidity-LLM"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float16,
    device_map="auto",
)

prompt = "Write a Solidity contract for a multi-signature wallet requiring 3 of 5 approvals"

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
    **inputs,
    max_new_tokens=1024,
    temperature=0.7,
    do_sample=True,
)

generated_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_code)
```

### Tips

* The 83% compilation success rate means roughly 1 in 5 outputs may need manual correction. Always compile and test the output.
* Pair the generated output with the Smart Contract Auditor to catch vulnerabilities before deployment.
* Use `float16` and `device_map="auto"` for efficient GPU memory usage.
* The model works well for standard patterns (ERC-20, ERC-721, staking, vesting) but may struggle with highly novel or complex contract logic.
* For production-critical contracts, consider using the cloud-based Smart Contract Generator instead.


---

# 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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
