Open Contracts is a platform designed to facilitate the sharing of best-practice code snippets for smart contracts on the TON (The Open Network) blockchain. Initiated under the The-Open-Contracts project, it empowers developers to contribute, discover, and utilize reusable code blocks to streamline smart contract development.
This API provides endpoints to create, retrieve, and list code blocks for smart contracts. It is built using the Gin framework in Go and follows RESTful principles.
/toc/v1/codeblock
Represents a stored code block in the system.
{
"_id": "string",
"author_id": "integer",
"title": "string",
"description": "string",
"rating": "integer",
"lang": "string",
"body": "string"
}Fields:
_id: Unique identifier for the code blockauthor_id: ID of the author who created the code blocktitle: Title of the code blockdescription: Description of the code blockrating: Rating of the code blocklang: Programming language (e.g., func, fift, tact, tolk)body: The code content
Data Transfer Object used for creating a code block.
{
"author_id": "integer",
"title": "string",
"description": "string",
"lang": "string",
"body": "string"
}Fields:
author_id: ID of the authortitle: Title of the code blockdescription: Description of the code blocklang: Programming languagebody: The code content
The API supports the following programming languages for code blocks:
funcfifttacttolk
- Method: POST
- Path:
/toc/v1/codeblock/create - Description: Creates a new code block.
- Request Body:
{ "author_id": 123, "title": "Sample Contract", "description": "A sample smart contract", "lang": "func", "body": "code content here" } - Responses:
- 200 OK:
{ "message": "create codeBlock" } - 400 Bad Request:
{ "error": "Invalid params" } - 500 Internal Server Error:
{ "error": "failed to create codeBlock" }
- 200 OK:
- Method: GET
- Path:
/toc/v1/codeblock/:id - Description: Retrieves a specific code block by its ID.
- Path Parameters:
id: The unique identifier of the code block.
- Responses:
- 200 OK:
{ "_id": "123", "author_id": 123, "title": "Sample Contract", "description": "A sample smart contract", "rating": 0, "lang": "func", "body": "code content here" } - 400 Bad Request:
{ "error": "invalid id" } - 500 Internal Server Error:
{ "error": "failed to get codeBlock" }
- 200 OK:
- Method: GET
- Path:
/toc/v1/codeblock/list - Description: Retrieves a list of all code blocks.
- Responses:
- 200 OK:
[ { "_id": "123", "author_id": 123, "title": "Sample Contract", "description": "A sample smart contract", "rating": 0, "lang": "func", "body": "code content here" } ] - 404 Not Found:
{ "error": "code blocks not found" } - 500 Internal Server Error:
{ "error": "failed to get codeBlocks" }
- 200 OK: