This part of the module focuses on understanding the role of Solidity in the development of Solana programs, exploring Solang, Solana accounts, and the differences between Solidity for Solana and Ethereum.
illustration
a
Solidity for Solana vs Ethereum

In this lesson, you'll learn:

  • How to adjust Solidity for use with Solana.
  • The key technical differences between Ethereum and Solana.

We'll briefly compare Solana and Ethereum's development environments. Unlike Ethereum's single-account system (handling both code and data), Solidity contracts on Solana use two accounts: one for the executable code (program account) and another for storage variables (data account).

Adapting Solidity for Solana

For Solidity to work with Solana, some changes are needed. In Solana's Solidity contracts, you'll find two accounts: the program account (holding the contract's executable code) and the data account (for storage variables). This is different from Ethereum's single-account system.

  • Solana accounts use a 32-byte key (the address type), different from Ethereum's 20-byte address. For example, a Solana address looks like 36VtvSbE6jVGGQytYWSaDPG7uZphaxEjpJHUUpuUbq4D, which isn't compatible with Ethereum's format like 0xE0f5206BBD039e7b0592d8918820024e2a7437b9.
  • Wallet addresses in Ethereum typically have 40 characters including the '0x' prefix, while Solana addresses are about 44 characters without a fixed prefix.
  • You'll need Solana version v1.8.1 for this.
  • Ethereum uses gas to manage resources in smart contracts, affecting costs. In Solana, they use compute units (200k per function), focusing on speed and not charging for these units.
  • Solana doesn't have the msg.sender function, and because of different signature algorithms, it lacks ecrecover() but has signatureVerify() for ed25519 signatures.
  • Solana doesn't support try-catch statements. If there's a failure, the transaction is stopped and reverted.
  • Error handling and reverts are limited in Solana, and it's not compatible with the ERC-20 interface.

Here's a comparison table highlighting these differences:

ConceptSolanaEthereum
Account Address Format32-byte key (address type)20-byte address
Wallet Address LengthAbout 44 characters40 characters (with 0x prefix)
Required Solana Versionv1.8.1-
Gas and Resource ManagementCompute Units (200k per function)Gas and EVM instructions
msg.sender FunctionNot AvailableAvailable
Signature VerificationsignatureVerify()ecrecover()
Try-Catch StatementsNot FunctionalAvailable
Error Handling and RevertsLimitedAvailable
ERC-20 CompatibilityNot CompatibleCompatible

In the next lesson, we'll provide a detailed technical comparison between Solana and Ethereum, focusing on their architectures and how they utilize Solidity.