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.
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).
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.
memecoin_smart_contract.rs
: The Rust source file containing the contract code.Cargo.toml
: Configuration file for dependencies, includingbincode
for serialization andsolana-program
for blockchain interactions.
- Rust programming language (latest stable version).
- Solana CLI and toolchain.
- An IDE or code editor (e.g., VS Code).
- Git for version control.
Include the following in Cargo.toml
:
[dependencies]
solana-program = "1.16.0"
bincode = { version = "1.3", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
git clone https://github.com/kaanyinaele/smartContract.git
cd smartContract
Compile the smart contract:
cargo build-bpf
Use the Solana CLI to deploy the program to the blockchain:
solana program deploy <path-to-compiled-binary>
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.
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.
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.
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.
Token data is serialized and deserialized using the bincode
crate to ensure efficient storage in Solana accounts.
The program uses ProgramError
to handle issues such as:
- Invalid instruction data.
- Insufficient funds.
- Mismatched token symbols.
- Incorrect account ownership.
Include tests in the tests
directory or directly in the src
file to ensure correctness of:
- Instruction unpacking.
- Account ownership checks.
- Token balance updates.
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.
- Ensure input data (e.g., symbol length, decimals, and supply) is properly validated to avoid unexpected behavior.
- Verify that all accounts interacting with the program are owned by the program.
- Use the
msg!
macro for logging critical actions and errors for better debugging.
- Support for token burning (reducing supply).
- Minting additional tokens to increase supply.
- Implement a proxy mechanism to allow program upgrades.
- Add support for metadata storage (e.g., token name and description).
- Fork the repository.
- Create a feature branch.
- Commit changes with descriptive messages.
- Submit a pull request for review.
This project is licensed under the MIT License.
For questions or support, contact the project maintainer via:
- Email: [email protected]
- GitHub Issues: Create a new issue