### Install foundry-zksync Fork Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/foundry/get-started Installs the foundry-zksync fork using a curl script and then runs the foundryup-zksync command to install forge, cast, and anvil. A terminal restart might be necessary after installation. ```bash curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bash foundryup-zksync ``` -------------------------------- ### Verify Foundry Installation Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/foundry/get-started Checks if the foundry-zksync installation was successful by executing `forge build --help` and verifying the presence of ZKSync configuration options in the output. ```bash forge build --help | grep -A 20 "ZKSync configuration:" ``` -------------------------------- ### Create New Abstract App with CLI (Bash) Source: https://docs.abs.xyz/abstract-global-wallet/getting-started This command uses `npx` to execute the `@abstract-foundation/create-abstract-app` package, initializing a new project with Abstract Global Wallet pre-configured. It requires Node.js and npm/yarn/pnpm to be installed. The command takes a project name as an argument and sets up the basic project structure. ```bash npx @abstract-foundation/create-abstract-app@latest my-app ``` -------------------------------- ### Create Hardhat Project Directory Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/get-started Initializes a new directory and navigates into it for a Hardhat project. This is the first step in setting up a new project environment. ```bash mkdir my-abstract-project && cd my-abstract-project ``` -------------------------------- ### Install Hardhat Abstract Dependencies Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/get-started Installs necessary Hardhat plugins and libraries for working with Abstract smart contracts. This includes `@matterlabs/hardhat-zksync` and `zksync-ethers`. ```bash npm install -D @matterlabs/hardhat-zksync zksync-ethers@6 ethers@6 ``` -------------------------------- ### Initialize Hardhat Project Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/get-started Initializes a new Hardhat project using the Hardhat CLI. This command sets up the basic project structure and configuration files. ```bash npx hardhat init ``` -------------------------------- ### Project Setup and Installation Source: https://docs.abs.xyz/build-on-abstract/applications/ethers Steps to create a new project directory, initialize a Node.js project, and install the necessary zksync-ethers and ethers libraries. Ensures the project is ready for Abstract development. ```bash mkdir my-abstract-app && cd my-abstract-app npm init -y npm install zksync-ethers@6 ethers@6 ``` -------------------------------- ### Create New Foundry Project Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/foundry/get-started Initializes a new project directory using the `forge init` command and then changes the current directory into the newly created project folder. ```bash forge init my-abstract-project && cd my-abstract-project ``` -------------------------------- ### Deploy Smart Contract Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/get-started Executes the deployment script on the specified Hardhat network. This command deploys the smart contract to either the testnet or mainnet environment. ```bash npx hardhat deploy-zksync --script deploy.ts --network abstractTestnet ``` ```bash npx hardhat deploy-zksync --script deploy.ts --network abstractMainnet ``` ```bash Running deploy script HelloAbstract was deployed to YOUR_CONTRACT_ADDRESS ``` -------------------------------- ### Deploy Smart Contract with Forge Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/foundry/get-started Deploys a smart contract using the `forge create` command. This command requires specifying the contract path, account, RPC URL, chain ID, and verification details. Separate configurations are provided for testnet and mainnet deployments. ```bash forge create src/Counter.sol:Counter \ --account myKeystore \ --rpc-url https://api.testnet.abs.xyz \ --chain 11124 \ --zksync \ --verify \ --verifier etherscan \ --verifier-url https://api-sepolia.abscan.org/api \ --etherscan-api-key TACK2D1RGYX9U7MC31SZWWQ7FCWRYQ96AD ``` ```bash forge create src/Counter.sol:Counter \ --account myKeystore \ --rpc-url https://api.mainnet.abs.xyz \ --chain 2741 \ --zksync \ --verify \ --verifier etherscan \ --verifier-url https://api.abscan.org/api \ --etherscan-api-key ``` ```text Deployer: 0x9C073184e74Af6D10DF575e724DC4712D98976aC Deployed to: 0x85717893A18F255285AB48d7bE245ddcD047dEAE Transaction hash: 0x2a4c7c32f26b078d080836b247db3e6c7d0216458a834cfb8362a2ac84e68d9f Contract successfully verified ``` -------------------------------- ### Configure foundry.toml for ZKSync Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/foundry/get-started Updates the `foundry.toml` file to set default project configurations, enable EVM extensions for system contract interactions, and define Etherscan settings for Abstract testnet and mainnet. ```toml [profile.default] src = 'src' libs = ['lib'] fallback_oz = true [profile.default.zksync] enable_eravm_extensions = true # Note: System contract calls (NonceHolder and ContractDeployer) can only be called with this set to true [etherscan] abstractTestnet = { chain = "11124", url = "", key = ""} # You can replace these values or leave them blank to override via CLI abstractMainnet = { chain = "2741", url = "", key = ""} # You can replace these values or leave them blank to override via CLI ``` -------------------------------- ### Import Wallet Keystore with Cast Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/foundry/get-started Imports a private key into a keystore file using the `cast wallet import` command. This process is interactive, prompting for the private key and a password for encryption. It's recommended to use a new wallet for deployment. ```bash cast wallet import myKeystore --interactive ``` -------------------------------- ### Write a Smart Contract for Abstract Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/get-started Defines a simple Solidity smart contract named `HelloAbstract`. This contract includes a `sayHello` function that returns a greeting string. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; contract HelloAbstract { function sayHello() public pure virtual returns (string memory) { return "Hello, World!"; } } ``` -------------------------------- ### Compile Smart Contract with ZKSync Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/foundry/get-started Compiles the smart contracts using the `forge build` command with the `--zksync` flag, which utilizes the zksolc compiler for Abstract compatibility. Compiled artifacts are placed in the `zkout` directory. ```bash forge build --zksync ``` -------------------------------- ### Compile Smart Contract for Abstract Mainnet Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/get-started Clears existing build artifacts and compiles smart contracts using the zksolc compiler for the Abstract mainnet. This command prepares the contract for deployment. ```bash npx hardhat clean npx hardhat compile --network abstractMainnet ``` -------------------------------- ### Write Deployment Script Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/get-started Creates a TypeScript deployment script for Hardhat. This script uses zksync-ethers and matterlabs/hardhat-zksync to deploy a specified contract artifact using the configured deployer wallet. ```bash mkdir deploy && touch deploy/deploy.ts ``` ```typescript import { Wallet } from "zksync-ethers"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import { Deployer } from "@matterlabs/hardhat-zksync"; import { vars } from "hardhat/config"; // An example of a deploy script that will deploy and call a simple contract. export default async function (hre: HardhatRuntimeEnvironment) { console.log(`Running deploy script`); // Initialize the wallet using your private key. const wallet = new Wallet(vars.get("DEPLOYER_PRIVATE_KEY")); // Create deployer object and load the artifact of the contract we want to deploy. const deployer = new Deployer(hre, wallet); // Load contract const artifact = await deployer.loadArtifact("HelloAbstract"); // Deploy this contract. The returned object will be of a `Contract` type, // similar to the ones in `ethers`. const tokenContract = await deployer.deploy(artifact); console.log( `${artifact.contractName} was deployed to ${await tokenContract.getAddress()}` ); } ``` -------------------------------- ### Solidity Contract Testing Example Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/foundry/testing-contracts Demonstrates setting up a test environment for a Solidity smart contract using Foundry. Includes contract deployment in the `setUp` function and a basic test case for a message getter/setter function. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import { Test } from "forge-std/Test.sol"; contract HelloWorldTest is Test { address owner; HelloWorld helloWorld; function setUp() public { owner = makeAddr("owner"); vm.prank(owner); helloWorld = new HelloWorld(); } function test_HelloWorld() public { helloWorld.setMessage("Hello, World!"); assertEq(helloWorld.getMessage(), "Hello, World!"); } } ``` ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract HelloWorld { string public message = "Hello, World!"; function setMessage(string memory newMessage) public { message = newMessage; } function getMessage() public view returns (string memory) { return message; } } ``` -------------------------------- ### Compile Smart Contract for Abstract Testnet Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/get-started Clears existing build artifacts and compiles smart contracts using the zksolc compiler for the Abstract testnet. This command prepares the contract for deployment. ```bash npx hardhat clean npx hardhat compile --network abstractTestnet ``` -------------------------------- ### Install foundry-zksync Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/foundry/installation Installs the foundry-zksync toolchain, a fork of Foundry for the ZKsync VM, using a provided installation script. It then runs the installer to set up forge, cast, and anvil. A terminal restart might be required after installation. ```bash curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bash ``` ```bash foundryup-zksync ``` -------------------------------- ### Set Deployer Private Key Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/get-started Configures the deployer account by setting the private key as a configuration variable using Hardhat's vars command. Ensure this private key is for a new wallet not associated with real funds. ```bash npx hardhat vars set DEPLOYER_PRIVATE_KEY ``` ```bash ✔ Enter value: · **************************************************************** ``` -------------------------------- ### Start Abstract Node with Docker Compose (Bash) Source: https://docs.abs.xyz/infrastructure/nodes/running-a-node Starts the Abstract node services defined in the testnet-external-node.yml file in detached mode. This command requires Docker and Docker Compose to be installed and configured. ```bash docker compose --file testnet-external-node.yml up -d ``` -------------------------------- ### Install System Contracts Library Source: https://docs.abs.xyz/how-abstract-works/native-account-abstraction/smart-contract-wallets Instructions for installing the Abstract system contracts library using package managers for Hardhat and Foundry. ```bash npm install @matterlabs/zksync-contracts ``` ```bash forge install matter-labs/era-contracts ``` -------------------------------- ### Write Counter Smart Contract Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/foundry/get-started Defines a simple Solidity smart contract named `Counter` with a state variable `number` and functions to set and increment this variable. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; contract Counter { uint256 public number; function setNumber(uint256 newNumber) public { number = newNumber; } function increment() public { number++; } } ``` -------------------------------- ### Create New Foundry Project Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/foundry/installation Demonstrates how to create a new Foundry project using the 'forge init' command and then navigate into the newly created project directory. ```bash forge init my-abstract-project && cd my-abstract-project ``` -------------------------------- ### Verify Smart Contract Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/get-started Verifies the deployed smart contract on the block explorer for public visibility and interaction. Replace YOUR_CONTRACT_ADDRESS with the actual deployed contract address. ```bash npx hardhat verify --network abstractTestnet YOUR_CONTRACT_ADDRESS ``` ```bash npx hardhat verify --network abstractMainnet YOUR_CONTRACT_ADDRESS ``` -------------------------------- ### Configure Hardhat for Abstract Networks Source: https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/get-started Updates the `hardhat.config.ts` file to include Abstract testnet and mainnet configurations. This enables Hardhat to connect to and deploy contracts on Abstract networks. ```typescript import { HardhatUserConfig } from "hardhat/config"; import "@matterlabs/hardhat-zksync"; const config: HardhatUserConfig = { zksolc: { version: "latest", settings: { // find all available options in the official documentation // https://docs.zksync.io/build/tooling/hardhat/hardhat-zksync-solc#configuration }, }, defaultNetwork: "abstractTestnet", networks: { abstractTestnet: { url: "https://api.testnet.abs.xyz", ethNetwork: "sepolia", zksync: true, chainId: 11124, }, abstractMainnet: { url: "https://api.mainnet.abs.xyz", ethNetwork: "mainnet", zksync: true, chainId: 2741, }, }, etherscan: { apiKey: { abstractTestnet: "TACK2D1RGYX9U7MC31SZWWQ7FCWRYQ96AD", abstractMainnet: "IEYKU3EEM5XCD76N7Y7HF9HG7M9ARZ2H4A", }, customChains: [ { network: "abstractTestnet", chainId: 11124, urls: { apiURL: "https://api-sepolia.abscan.org/api", browserURL: "https://sepolia.abscan.org/" }, }, { network: "abstractMainnet", chainId: 2741, urls: { apiURL: "https://api.abscan.org/api", browserURL: "https://abscan.org/" }, }, ], }, solidity: { version: "0.8.24", }, }; export default config; ``` -------------------------------- ### Solidity Contract Deployment via CREATE2 Source: https://docs.abs.xyz/how-abstract-works/evm-differences/contract-deployment Demonstrates deploying a new contract instance using the CREATE2 opcode in Solidity. This method leverages the `new` keyword with a specified salt for deterministic deployment. ```solidity import "./MyContract.sol"; contract MyContractFactory { function create2MyContract(bytes32 salt) public { MyContract myContract = new MyContract{salt: salt}(); } } ``` ```solidity contract MyContract { function sayHello() public pure returns (string memory) { return "Hello World!"; } } ```