Skip to content

Open-source repository containing smart contract snippets to make developing smart contracts easier.

License

Notifications You must be signed in to change notification settings

Shahupdates/SmartContractSnippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmartContractSnippets

1bd2b81e66e645d47458c6a89e8f5a5b

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.

Contents

  1. Ethereum
  2. BinanceSmartChain
  3. Solana
  4. Polkadot

GUI Application

We have also provided a simple GUI application to help you build smart contracts from the snippets. Here's how to use it:

  1. Run the application by executing python main.py in the terminal.
  2. In the left pane of the application, select the snippet you want to insert.
  3. Click the "Insert snippet" button.
  4. 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.

Basic structure as a directory tree

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

Ethereum

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.

BinanceSmartChain

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 Ethereum Ownable.sol and provides a basic contract that has an owner address, and provides authorization control functions.

  • SafeMath.sol: This file is similar to the Ethereum SafeMath.sol and provides a library that helps avoid integer overflow and underflow errors.

Solana

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.

Polkadot

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.

Usage

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.

Contributing

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.

License

MIT

About

Open-source repository containing smart contract snippets to make developing smart contracts easier.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published