Coder Social home page Coder Social logo

foundry-zksync-era's Introduction

This solution is deprecated, please refer to https://github.com/matter-labs/foundry-zksync for foundry support with zkSync

Foundry Plugin for zkSync Era

Preview

Overview

This plugin allows for the compilation & deployment of contracts to the zkSync Era network within a foundry project. zkSync Era uses a custom compiler and deployment process different from other EVM networks, this plugin simplifies this process.

Requirements

This plugin assumes you have solc installed and in your path.

Installation / Setup

Install this project as a dependancy:

forge install omurovec/foundry-zksync-era

Import Deployer.sol into your deployment script and use as follows:

// Script.s.sol

import "lib/foundry-zksync-era/script/Deployer.sol";

...
// Diamond proxy addresses, last updated 24.03.2023
address DIAMOND_PROXY_MAINNET = 0x32400084C286CF3E17e7B677ea9583e60a000324;
address DIAMOND_PROXY_GOERLI = 0x1908e2BF4a88F91E4eF0DC72f02b8Ea36BEa2319;

// Provide zkSync compiler version and address of the diamond proxy on L1
Deployer deployer = new Deployer("1.3.7", DIAMOND_PROXY_MAINNET);

// Provide path to contract, input params & salt
// Returns deployment address on L2
deployer.deployFromL1("src/Counter.sol", new bytes(0), bytes32(uint256(1337)));

Note: The Diamond Proxy address is the address of the L1 contract that handles all interactions with the zkSync network. This address will always be the same as the bridge and can be found by attempting to bridge assets at https://portal.zksync.io/bridge

Ensure your private key is in your env:

PRIVATE_KEY=""

Enable read/write permissions in your foundry.toml:

fs_permissions = [{ access = "read-write", path = "./"}]

Deploy your contracts using the script you created:

forge script script/Script.s.sol --ffi --broadcast --rpc-url L1_RPC_URL

The contract address is returned from the deployFromL1() function. The transaction hash of the deployment on L2 will be returned in the execution of the transaction. It is dependant on the block timestamp so it can not be accurately derrived within the script.

Note: It's also recommended to add lib/zksolc* to your project's .gitignore

Notes

This is a work in progress so it does not have all the features of it's counterparty hardhat-zksync. Some things to note:

  • This project currently only supports deployment from L1. Direct deployment from L2 requires custom data to be passed in to the EIP-712 transaction (see zkSync docs).

  • The _l2GasLimit & _l2GasPerPubdataByteLimit params for requestL2Transaction() are currently hardcoded to their max values for convenience.

Contribution

This has just been a quick passion project so far but would love any help on making this a more feature rich project & a go-to for anyone using foundry + zksync era so feel free to open any issues or PRs that you think would be useful.

foundry-zksync-era's People

Contributors

omurovec avatar shafu0x avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.