Skip to content

kaanyinaele/smartContract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Memecoin Smart Contract Documentation

Overview

The Memecoin smart contract is a Rust-based program designed to run on the Solana blockchain. It provides functionality to create and manage a custom token, including features for initializing a token and transferring it between accounts.


Features

1. Token Initialization

The contract allows the creation of a custom token with the following properties:

  • Total Supply: The total number of tokens to be created.
  • Symbol: A unique identifier for the token (up to 32 characters).
  • Decimals: The precision for fractional amounts (maximum 18).

2. Token Transfers

Users can transfer tokens between accounts with the following safeguards:

  • Validation of sufficient balance in the sender’s account.
  • Ensuring both sender and receiver accounts belong to the same token.
  • Deduction of tokens from the sender’s balance and addition to the receiver’s balance.

File Structure

Main Files

  • memecoin_smart_contract.rs: The Rust source file containing the contract code.
  • Cargo.toml: Configuration file for dependencies, including bincode for serialization and solana-program for blockchain interactions.

Prerequisites

Development Environment

  • Rust programming language (latest stable version).
  • Solana CLI and toolchain.
  • An IDE or code editor (e.g., VS Code).
  • Git for version control.

Dependencies

Include the following in Cargo.toml:

[dependencies]
solana-program = "1.16.0"
bincode = { version = "1.3", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }

Usage Instructions

1. Clone the Repository

git clone https://github.com/kaanyinaele/smartContract.git
cd smartContract

2. Build the Program

Compile the smart contract:

cargo build-bpf

3. Deploy to Solana

Use the Solana CLI to deploy the program to the blockchain:

solana program deploy <path-to-compiled-binary>

4. Interact with the Program

You can use Solana client libraries (e.g., solana-web3.js) or the CLI to interact with the program. Example interactions include:

  • Initializing a Token:
    • Provide the total supply, symbol, and decimals as input data.
  • Transferring Tokens:
    • Specify sender and receiver accounts along with the transfer amount.

Implementation Details

Key Functions

process_instruction

The entry point of the program. It parses the instruction data and routes it to the appropriate handler:

  • initialize_memecoin for token initialization.
  • transfer_memecoin for token transfers.

initialize_memecoin

Initializes a new token by:

  • Checking ownership of the account.
  • Verifying the account is not already initialized.
  • Storing the token's metadata (supply, symbol, and decimals) in the account.

transfer_memecoin

Transfers tokens between accounts by:

  • Ensuring the sender has signed the transaction.
  • Validating ownership and token compatibility.
  • Updating balances for both sender and receiver accounts.

Data Serialization

Token data is serialized and deserialized using the bincode crate to ensure efficient storage in Solana accounts.

Error Handling

The program uses ProgramError to handle issues such as:

  • Invalid instruction data.
  • Insufficient funds.
  • Mismatched token symbols.
  • Incorrect account ownership.

Testing the Program

Unit Tests

Include tests in the tests directory or directly in the src file to ensure correctness of:

  • Instruction unpacking.
  • Account ownership checks.
  • Token balance updates.

Integration Tests

Use the Solana testing framework (solana-program-test) to simulate end-to-end interactions:

  • Deploy the program to a local test validator.
  • Test token initialization and transfers in a controlled environment.

Security Considerations

Input Validation

  • Ensure input data (e.g., symbol length, decimals, and supply) is properly validated to avoid unexpected behavior.

Account Ownership

  • Verify that all accounts interacting with the program are owned by the program.

Error Logging

  • Use the msg! macro for logging critical actions and errors for better debugging.

Future Improvements

Feature Enhancements

  • Support for token burning (reducing supply).
  • Minting additional tokens to increase supply.

Upgradeability

  • Implement a proxy mechanism to allow program upgrades.

Token Metadata

  • Add support for metadata storage (e.g., token name and description).

Contribution Guidelines

  1. Fork the repository.
  2. Create a feature branch.
  3. Commit changes with descriptive messages.
  4. Submit a pull request for review.

License

This project is licensed under the MIT License.


Contact

For questions or support, contact the project maintainer via:


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages