info

Please note that zkApp programmability is not yet available on Mina Mainnet, but zkApps can now be deployed to Berkeley Testnet.

# zkApps for Ethereum Developers

Mina and Ethereum are both decentralized, programmable, layer-one blockchains, but they are designed in fundamentally different ways. The Ethereum network verifies transaction execution by having every node execute every transaction. While this design solves a real problem, it also imposes some severe limitations on privacy and scalability.

The Mina Protocol works differently. It verifies transactions (and previous blocks) cryptographically using recursive zero-knowledge proofs. Smart contract code is written in TypeScript and executes off chain. Mina nodes only need to verify a small proof in order to validate the associated execution. Better still, the proof does not reveal any information about the underlying computation, meaning developers can choose whether their inputs and outputs should be public or private, depending on the requirements of their application.

## At a Glance​

Ethereum Smart ContractsMina zkApps
LanguageSmart contracts are written in Solidity.zkApp smart contracts are written using SnarkyJS (a TypeScript library).
Execution EnvironmentSmart contracts run on every Ethereum node.zkApps run client side in a user’s web browser, and publish only a small validity proof which is verified by the Mina nodes.
Transaction CostExecution costs are variable, and determined using a gas model.Execution costs are small, and constant because the Mina nodes are verifying the same size proof regardless of the amount of client-side computation.
Application StorageEthereum is designed around the idea that storage, and computation are inherently coupled; all state must live on every Ethereum node.Mina’s design allows state, and computation to be decoupled so that application state can live anywhere; developers can choose a solution that fits their cost/security requirements best.
Developer ToolingNew developer tools with unusual patterns like Hardhat, and Truffle are needed in order to manage the deployment of Ethereum smart contracts.The Mina zkApp CLI manages scaffolding, linting, testing, and deployment using common JavaScript/TypeScript tools you are already familiar with.
ScalingEthereum nodes must execute every transaction directly making horizontal scaling hard.Mina’s recursive zero-knowledge proofs allow snark-workers to compress the blockchain, and developers to compress transactions using native rollups for exponential scaling.
ConsensusEthereum nodes must download the entire block history (~700GB) in order to verify the current finalized chain state.Mina clients can verify the current finalized state using a single 22KB recursive zero-knowledge proof.

## Example Code​

import { Field, SmartContract, state, State, method } from 'snarkyjs';export class Add extends SmartContract {  /* The state decorator tells SnarkyJS to store/retrieve num from the Mina  blockchain */  /* The Field type represents elements of a finite field (similar to uint256  for practical purposes, but loops back to 1 after overflowing) */  @state(Field) num = State<Field>();  // Initialize the contract (similar to a constructor in Solidity)  init() {    super.init();    // Set num equal to a Field element of value 1 on contract deployment    this.num.set(Field(1));  }  /* The method decorator tells SnarkyJS to be ready to generate a proof of  execution any time this method is called */  @method update() {    // Get the state of num from the Mina blockchain and set it to currentState    const currentState = this.num.get();    /* Calling add instead of using the JS infix addition operator enables    SnarkyJS to prove that the addition is done correctly */    const newState = currentState.add(2);    /* Set the state of num on the Mina blockchain equal to newState (this    state update will not happen unless the transaction is accompanied by    a valid proof of execution) */    this.num.set(newState);  }}

## FAQ​

### How does Mina bridge to Ethereum?​

Mina proofs are small and easy to verify; this means that any Turing complete blockchain (like Ethereum) can validate the entire Mina state in a single transaction using a bridge contract. These are a bit different from existing bridging solutions because they don't require additional security assumptions. Think of them as full Mina nodes that are implemented in smart contracts on other chains. They validate the Mina state in exactly the same way a Mina block producer would and expose Mina directly to any other contract. The Nil Foundation is working on the first of these bridges for Ethereum and other EVM-compatible networks.

### Have another question?​

Reach out in the #zkapps-developers channel on Mina Protocol Discord. It's better when we learn together.