Generate Solidity Smart Contracts Using Natural Language.
This project provides a web interface to generate Solidity smart contracts from natural language descriptions. It leverages OpenAI's GPT-4 API to generate code based on user input and offers predefined templates for common contract types such as ERC-20 tokens and voting systems.
- Generate Solidity smart contracts from text descriptions.
- Supports predefined contract types (ERC-20 Token, Voting System).
- Custom contract generation using GPT-4.
- Download generated contracts as
.sol
files.
- Python 3.7 or higher
- Streamlit
- OpenAI API Key
-
Clone the repository:
git clone https://github.com/yourusername/smart-contract-generator.git cd smart-contract-generator
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up your OpenAI API Key:
- For Unix-based systems:
export OPENAI_API_KEY="your-openai-api-key"
- For Windows:
set OPENAI_API_KEY=your-openai-api-key
- For Unix-based systems:
-
Run the Streamlit application:
streamlit run app.py
- Open your web browser and navigate to the URL provided by Streamlit (typically
http://localhost:8501
). - Select the contract type from the sidebar.
- Enter a description of your smart contract scenario.
- Click the "Generate Smart Contract" button.
- Review the generated Solidity code.
- Download the generated smart contract using the download button.
Unit tests are provided to validate the functionality of the smart contract generation. To run the tests, use the following command:
pytest tests/
The generated Solidity code is validated for syntax correctness using solc
. Ensure you have the Solidity compiler installed and run:
python test_solidity.py
The primary design goal of this project was to create a user-friendly interface for generating Solidity smart contracts. Key considerations include:
- Simplicity: The interface is straightforward, allowing users to generate contracts with minimal input.
- Flexibility: Supports predefined contract types and custom contract generation using natural language input.
- Extensibility: The modular design enables easy addition of new contract templates and features.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please read the CONTRIBUTING guide for more details.
- OpenAI for providing the GPT-4 API.
- Streamlit for the amazing web framework.