This repository contains smart contract code snippets for various blockchain platforms. It is designed to help developers kickstart their smart contract development by providing foundational pieces of code.
We have also provided a simple GUI application to help you build smart contracts from the snippets. Here's how to use it:
- Run the application by executing
python main.py
in the terminal. - In the left pane of the application, select the snippet you want to insert.
- Click the "Insert snippet" button.
- The content of the snippet will be inserted at the cursor position in the right pane, which functions as a basic text editor.
You can repeat these steps to insert as many snippets as you need. Remember to review and modify the inserted code as necessary.
Please note that this application requires Python and Tkinter to be installed.
SmartContractSnippets
├── README.md
├── Ethereum
│ ├── README.md
│ ├── ERC20Basic.sol
│ ├── ERC721Basic.sol
│ ├── Ownable.sol
│ └── SafeMath.sol
├── BinanceSmartChain
│ ├── README.md
│ ├── BEP20Basic.sol
│ ├── BEP721Basic.sol
│ ├── Ownable.sol
│ └── SafeMath.sol
├── Solana
│ ├── README.md
│ ├── helloworld
│ │ ├── src
│ │ │ └── lib.rs
│ │ └── Cargo.toml
└── Polkadot
│ ├── README.md
│ └── flipper
│ ├── lib.rs
│ └── Cargo.toml
└── main.py
The Ethereum directory contains Solidity contract snippets that can be used as building blocks for developing more complex contracts on the Ethereum network:
-
ERC20.sol
: This file provides a basic implementation of an ERC20 token contract, following the ERC20 standard. It includes functions for transferring tokens, checking balances, and allowing other contracts to spend tokens on the owner's behalf. -
ERC721.sol
: This file provides a basic implementation of an ERC721 token contract, following the ERC721 standard, also known as "Non-Fungible Tokens" (NFTs). It includes functions for transferring tokens, checking token ownership, and allowing other contracts to spend tokens on the owner's behalf. -
Ownable.sol
: This file provides a basic contract that has an owner address, and provides authorization control functions. This simplifies the implementation of "user permissions". -
SafeMath.sol
: This file provides a library that helps avoid integer overflow and underflow errors. It provides safe versions of addition, subtraction, multiplication, and division operations.
The Binance Smart Chain directory contains Solidity contract snippets, similar to Ethereum, which are compliant with the Binance Smart Chain (BSC):
-
BEP20.sol
: This file provides a basic implementation of a BEP20 token contract, following the BEP20 standard (analogous to ERC20). It includes functions for transferring tokens, checking balances, and allowing other contracts to spend tokens on the owner's behalf. -
BEP721.sol
: This file provides a basic implementation of a BEP721 token contract, following the BEP721 standard (analogous to ERC721). It includes functions for transferring tokens, checking token ownership, and allowing other contracts to spend tokens on the owner's behalf. -
Ownable.sol
: This file is similar to the EthereumOwnable.sol
and provides a basic contract that has an owner address, and provides authorization control functions. -
SafeMath.sol
: This file is similar to the EthereumSafeMath.sol
and provides a library that helps avoid integer overflow and underflow errors.
The Solana directory contains Rust contract snippets compatible with the Solana network:
-
helloworld/src/lib.rs
: This file provides a simple "Hello World!" smart contract in Rust. It demonstrates the basic structure of a Solana program, including a function to process instructions. -
helloworld/Cargo.toml
: This file is the package configuration file for the Hello World contract. It includes the necessary dependencies for the smart contract.
The Polkadot directory contains Ink! contract snippets compatible with the Polkadot network:
-
flipper/lib.rs
: This file provides a simple Ink! contract called "Flipper", which has a boolean value that can be flipped and retrieved. It demonstrates how to define a contract, a storage item, messages, and a constructor in Ink!. -
flipper/Cargo.toml
: This file is the package configuration file for the Flipper contract. It includes the necessary dependencies for the smart contract.
To use these snippets, copy the file into your project directory and include them in your project as necessary. Remember to replace any placeholder values with your own. Refer to the individual README files in each directory for more detailed usage instructions.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Ensure your PR includes tests for any new functionality or bug fixes.