Getting Started

Project Setup

We recommend scaffolding your project using the zksync-cli.

Configuration

Set up your project with the following configuration:

Contract Deployment

Basic Deployment

Here’s how to deploy a contract without using the paymaster:

import { utils } from "zksync-ethers";

const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact("Your_Contract");
const contract = await deployer.deploy(
    artifact,
    constructorArguments || []
);

Deployment with Paymaster

During the alpha stage, you’ll need to use our Paymaster to sponsor transactions. Here’s how to deploy using the paymaster:

import { utils } from "zksync-ethers";

const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact("Your_Contract");

const params = utils.getPaymasterParams(
  "0x98546B226dbbA8230cf620635a1e4ab01F6A99B2", // Paymaster address
  {
    type: "General",
    innerInput: new Uint8Array(),
  }
);

const contract = await deployer.deploy(
    artifact,
    constructorArguments || [], 
    {
      customData: {
        paymasterParams: params,
        gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
    },
});

Proxy Deployment

To deploy proxy contracts with paymaster support:

import { utils } from "zksync-ethers";

const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact("Your_Contract");

await hre.zkUpgrades.deployProxy(deployer.zkWallet, artifact, [initializerArgs], 
 {
   initializer: "initialize",
   paymasterProxyParams: params,
   paymasterImplParams: params,
 }
);

Contract Interaction

To interact with deployed contracts using the paymaster:

import { utils } from "zksync-ethers";

const paymasterParams = utils.getPaymasterParams(
  "0x98546B226dbbA8230cf620635a1e4ab01F6A99B2",
  {
    type: "General",
    innerInput: new Uint8Array(),
  }
);

const tx = await contract.yourFunction(params, {
  customData: {
    gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
    paymasterParams: paymasterParams,
  },
});

Contract Verification

You can verify contracts on both Sophscan and Sophon’s explorer:

npx hardhat verify --network sophonTestnet DEPLOYED_CONTRACT_ADDRESS constructor_arguments