bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 10쪽 중 2쪽
## Counter Contract Deployment
### Basic Deployment
<Warning>
If you run into deployment or interaction issues, always check for possible short-circuit errors
caused by environment variables not being properly exposed to the foundry script. You can do so by
running `source .env` before running the script or check the variable in your env by running `echo
$VARIABLE_NAME`.
</Warning>
```
source .env && forge create ./src/Counter.sol:Counter \
--rpc-url testnet --private-key $PRIVATE_KEY --zksync
```
### Deployment and Verification
Same as [Basic Deployment](#basic-deployment) but you append the `--verify` flag and use the `--verifier zksync` flag to specify the verifier to use the Sophon Explorer or `--verifier etherscan` to use Sophscan.
<Note>This will only verify on **Sophscan**</Note>
```
source .env && forge create ./src/Counter.sol:Counter --rpc-url testnet \
--private-key $PRIVATE_KEY --zksync --verifier zksync \
--verifier-url $TESTNET_VERIFIER_URL
```
### Deployment Using Paymaster
Same as [Basic Deployment](#basic-deployment) but you append the `--zk-paymaster-address` flag
<Note>
The paymaster allows you to perform gasless transactions, so there's no need to have a SOPH
balance
</Note>
```
source .env && forge create ./src/Counter.sol:Counter \
--rpc-url testnet --private-key $PRIVATE_KEY --zksync \
--zk-paymaster-address $PAYMASTER_ADDRESS \
--zk-paymaster-input $(cast calldata "general(bytes)" "0x")
```
### Deployment With Paymaster and Verification (All-in-One)
```
source .env && forge create ./src/Counter.sol:Counter \
--rpc-url testnet --private-key $PRIVATE_KEY --zksync \
--zk-paymaster-address $PAYMASTER_ADDRESS \
--zk-paymaster-input $(cast calldata "general(bytes)" "0x") --verify \
--verifier zksync --verifier-url $TESTNET_VERIFIER_URL
```
## Deploy Contracts Using Foundry Scripts
### Deployment Using Script
```
source .env && forge script ./script/Counter.s.sol \
--rpc-url testnet --private-key $PRIVATE_KEY --zksync --broadcast
```
### Deployment Using Script and Verification
Same as [Deployment Using Script](#deployment-using-script) but you append the `--verify` flag
<Note>This will only verify on **Sophscan**</Note>
```
source .env && forge create ./src/Counter.sol:Counter \
--rpc-url testnet --private-key $PRIVATE_KEY --zksync --verify \
--verifier zksync --verifier-url $TESTNET_VERIFIER_URL
```
### Deployment Using Script With Paymaster
Same as [Deployment Using Script](#deployment-using-script) but you append the `--zk-paymaster-address` flag
<Note>This will only verify on **Sophscan**</Note>
To use the paymaster within a script, you have 2 options: using a **cheatcode** or making a **low-level** call:
#### Using a Foundry Cheatcode
* Install [forge-zksync-std library](https://foundry-book.zksync.io/zksync-specifics/forge-zksync-std)
* Use the [vmExt.zkUsePaymaster](https://foundry-book.zksync.io/zksync-specifics/cheatcodes/zk-use-paymaster) cheatcode
* For your convenience, you can copy-paste the following script:
```solidity theme={null}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Script, console} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
import {TestExt} from "lib/forge-zksync-std/src/TestExt.sol";
contract CounterScript is Script, TestExt {
Counter public counter;
function setUp() public {}
function run() public {
vm.startBroadcast();
// Encode paymaster input
bytes memory paymaster_encoded_input = abi.encodeWithSelector(
bytes4(keccak256("general(bytes)")),
bytes("0x")
);
vmExt.zkUsePaymaster(vm.envAddress("PAYMASTER_ADDRESS"), paymaster_encoded_input);
counter = new Counter();
vm.stopBroadcast();
}
}
```
You can now run the following command
```
source .env && forge script ./script/Counter.s.sol \
--rpc-url testnet --private-key $PRIVATE_KEY --zksync --broadcast
```
#### Using a Low-Level Call (in Case You Can't Install the Cheatcode Library)
For your convenience, you can copy-paste the following script:
<Info>Here we use `address(vm).call`</Info>
```solidity theme={null}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Script, console} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
import {TestExt} from "lib/forge-zksync-std/src/TestExt.sol";
contract CounterScript is Script, TestExt {
Counter public counter;
function setUp() public {}
function run() public {
vm.startBroadcast();
// Encode paymaster input
bytes memory paymaster_encoded_input = abi.encodeWithSelector(
bytes4(keccak256("general(bytes)")),
bytes("0x")
);
(bool success, ) = address(vm).call(
abi.encodeWithSignature(
"zkUsePaymaster(address,bytes)",
vm.envAddress("PAYMASTER_ADDRESS"),
paymaster_encoded_input
)
);
require(success, "zkUsePaymaster() call failed");
counter = new Counter();
vm.stopBroadcast();
}
}
```
You can now run the following command:
```
source .env && forge script ./script/Counter.s.sol \
--rpc-url testnet --private-key $PRIVATE_KEY --zksync --broadcast
```
### Deployment Using Script With Paymaster and Verification
Same as [Deployment Using Script With Paymaster](#deployment-using-script-with-paymaster) but you append the `--verify` flag
<Note>This will only verify on **Sophscan**</Note>
```
source .env && forge script ./script/Counter.s.sol \
--rpc-url testnet --private-key $PRIVATE_KEY --zksync --broadcast --verify \
--verifier etherscan --verifier-url $SOPHSCAN_TESTNET_VERIFIER_URL
```
## Contract Verification
If you want to verify an already deployed contract, you can do so on [Sophscan](https://sophscan.xyz) (an Etherscan-like explorer) and/or on [Sophon's Explorer](https://explorer.sophon.xyz).
**On Sophscan**
```
source .env && forge verify-contract COUNTER_CONTRACT_ADDRESS \
./src/Counter.sol:Counter:Counter --watch --rpc-url testnet --zksync \
--verifier zksync --verifier-url $SOPHSCAN_TESTNET_VERIFIER_URL
```
**On Sophon's Explorer**
```
forge verify-contract COUNTER_CONTRACT_ADDRESS ./src/Counter.sol:Counter \
--watch --verifier zksync --verifier-url $SOPHON_VERIFIER_URL --zksync
```
### Using Libraries
If your contract relies on external libraries, you need to build it with the linked libraries during deployment. For example:
<Warning>
If you deploy a library via the EVM Equivalence Module, you can't link it to a zkEVM contract.
We advise to keep your libraries inline, in possible. Check how to compile non-inlinable libraries [here](https://docs.zksync.io/zksync-era/tooling/hardhat/guides/compiling-libraries).
</Warning>
```
forge build --zksync --libraries ./contracts/util/SignatureChecker.sol:SignatureChecker:0xb0A2cf27Bf984bd0c56dCFb37C9DA0F2c5028844
```
This ensures the library is properly linked during the build and deploy process, enabling verification to succeed.
### Contracts With Constructor Params
If your contract receives constructor params, you can use the `--constructor-args` flag:
Modify your Counter contract to receive a constructor param:
```solidity theme={null}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract Counter {
uint256 public number;
constructor(uint256 _number) {
number = _number;
}
function setNumber(uint256 newNumber) public {
number = newNumber;
}
function increment() public {
number++;
}
}
```
You can now run:
```shell theme={null}
forge create ./src/CounterWithConstructorParams.sol:Counter \
--rpc-url testnet --private-key $PRIVATE_KEY --zksync \
--constructor-args "$(cast abi-encode "constructor(uint256)" "123")"
```
<Tip>
To verify or use the paymaster, you can use the flags `--verify` and/or `----zk-paymaster-address`
as explained above.
</Tip>
## Check if a contract is whitelisted by the paymaster
Before making calls to a newly deployed contract using a paymaster, it's important to verify that the contract has been added to the paymaster's whitelist. Our automated contract whitelisting service typically takes 2-3 seconds to whitelist new contracts under normal network conditions. While optional, checking the whitelist status before proceeding makes deployment scripts more robust by ensuring contracts are ready to interact with the paymaster.
The code below provides a reference implementation for checking the whitelist status:
```solidity theme={null}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Script, console} from "forge-std/Script.sol";
import {Counter} from "../src/Counter.sol";
import {TestExt} from "lib/forge-zksync-std/src/TestExt.sol";
interface IRestrictionContract {
function contractWhitelist(address) external view returns (bool);
}
contract CounterScript is Script, TestExt {
Counter public counter;
function setUp() public {}
function run() public {
vm.startBroadcast();
address restrictionContractAddress = vm.envAddress("RESTRICTION_CONTRACT");
address paymasterAddress = vm.envAddress("PAYMASTER_ADDRESS");
uint256 waitTime = 5_000; // wait time in milliseconds
uint256 maxAttempts = 5;
bool isWhitelisted = false;
uint256 attempts = 0;
if (restrictionContractAddress != address(0)) {
IRestrictionContract restrictionContract = IRestrictionContract(restrictionContractAddress);
while (!isWhitelisted && attempts < maxAttempts) {
try restrictionContract.contractWhitelist(address(this)) returns (bool whitelisted) {
isWhitelisted = whitelisted;
if (isWhitelisted) {
console.log("Contract is whitelisted on restriction contract!");
break;
} else {
attempts++;
if (attempts < maxAttempts) {
console.log("Contract not yet whitelisted. Waiting before retrying...");
vm.sleep(waitTime);
} else {
console.log("Contract still not whitelisted after max attempts. Proceeding anyway.");
}
}
} catch {
console.log("Error checking whitelist status. Retrying...");
attempts++;
if (attempts < maxAttempts) {
vm.sleep(waitTime);
}
}
}
}
// Encode paymaster input
bytes memory paymaster_encoded_input = abi.encodeWithSelector(
bytes4(keccak256("general(bytes)")),
bytes("0x")
);
(bool success, ) = address(vm).call(
abi.encodeWithSignature(
"zkUsePaymaster(address,bytes)",
paymasterAddress,
paymaster_encoded_input
)
);
require(success, "zkUsePaymaster() call failed");
counter = new Counter();
vm.stopBroadcast();
}
}
```
# Hardhat/Ethers
Source: https://docs.sophon.xyz/build/interact/hardhat
Learn about how to develop on Sophon using Hardhat
<Warning>
This guide is retained only for maintaining an existing Sophon v1 deployment.
Do not start a new production deployment on the chain.
</Warning>
## Getting Started
### Project Setup
We recommend scaffolding your project using the [zksync-cli](https://github.com/matter-labs/zksync-cli).
### Configuration
<Tip>
In order to obtain a Sophscan API Key, you need to create an account and get an API Key
[here](https://docs.sophscan.xyz/getting-started/viewing-api-usage-statistics).
</Tip>
Set up your project with the following configuration:
<CodeGroup>
```typescript hardhat.config.ts theme={null}
import type { HardhatUserConfig } from "hardhat/config";
import "@matterlabs/hardhat-zksync";
import * as dotenv from "dotenv";
// Load environment variables from .env file
dotenv.config();
const config: HardhatUserConfig = {
defaultNetwork: "sophonMainnet",
networks: {
hardhat: {
zksync: true,
},
sophonMainnet: {
url: "https://rpc.sophon.xyz",
ethNetwork: "mainnet",
verifyURL: "https://verification-explorer.sophon.xyz/contract_verification",
browserVerifyURL: "https://explorer.sophon.xyz/",
enableVerifyURL: true,
zksync: true,
accounts: [process.env.WALLET_PRIVATE_KEY as string],
},
},
zksolc: {
version: "latest",
settings: {},
},
solidity: {
version: "0.8.27",
},
etherscan: {
enabled: true,
apiKey: {
sophonMainnet: process.env.ETHERSCAN_SOPHON_API_KEY as string,
},
customChains: [
{
network: "sophonMainnet",
chainId: 50104,
urls: {
apiURL: "https://api.sophscan.xyz/api",
browserURL: "https://sophscan.xyz",
},
},
],
},
};
export default config;
```
```env .env theme={null}
WALLET_PRIVATE_KEY=your_private_key_here
ETHERSCAN_SOPHON_API_KEY=your_sophscan_api_key_here
```
</CodeGroup>
## Contract Deployment
### Basic Deployment
Here's how to deploy a contract without using the paymaster:
```typescript theme={null}
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:
```typescript theme={null}
import { Provider, Wallet, utils } from "zksync-ethers";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { HardhatRuntimeEnvironment } from "hardhat/types";
export default async function (hre: HardhatRuntimeEnvironment) {
const provider = new Provider(hre.network.config.url);
const wallet = new Wallet(process.env.WALLET_PRIVATE_KEY!, provider);
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,
[], // Constructor arguments
undefined, // Deployment type (use undefined for regular contract deployment)
{
customData: {
paymasterParams: params,
gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
},
}
);
}
```
### Proxy Deployment
To deploy proxy contracts with paymaster support:
```typescript theme={null}
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:
```typescript theme={null}
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:
```bash theme={null}
npx hardhat verify --network sophonMainnet DEPLOYED_CONTRACT_ADDRESS constructor_arguments
```
## Check if a contract is whitelisted by the paymaster
Before making calls to a newly deployed contract using a paymaster, it's important to verify that the contract has been added to the paymaster's whitelist. Our automated contract whitelisting service typically takes 2-3 seconds to whitelist new contracts under normal network conditions. While optional, checking the whitelist status before proceeding makes deployment scripts more robust by ensuring contracts are ready to interact with the paymaster.
The code below provides a reference implementation for checking the whitelist status:
```typescript theme={null}
const restrictionContractAddress = (hre.network.config as unknown as CustomNetworkConfig)
?.restrictionContract;
if (restrictionContractAddress && usePaymaster) {
const contractAddress = await contract.getAddress();
logger.info(
`Checking if ${contractName} (${contractAddress}) is whitelisted on restriction contract...`
);
// Create interface for the restriction contract
const restrictionContractABI = [
{
inputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
name: "contractWhitelist",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
],
stateMutability: "view",
type: "function",
},
];
const provider = hre.ethers.provider;
const restrictionContract = new hre.ethers.Contract(
restrictionContractAddress,
restrictionContractABI,
provider
);
let isWhitelisted = false;
let attempts = 0;
const maxAttempts = 5;
while (!isWhitelisted && attempts < maxAttempts) {
try {
isWhitelisted = await restrictionContract.contractWhitelist(contractAddress);
if (isWhitelisted) {
logger.info(`${contractName} is now whitelisted on restriction contract!`);
} else {
attempts++;
if (attempts < maxAttempts) {
logger.info(
`${contractName} is not yet whitelisted. Waiting ${
waitTime / 1000
} seconds before retry (attempt ${attempts}/${maxAttempts})...`
);
await new Promise((resolve) => setTimeout(resolve, waitTime));
} else {
logger.warn(
`${contractName} is still not whitelisted after ${maxAttempts} attempts. Proceeding anyway, but paymaster transactions might fail.`
);
}
}
} catch (error) {
logger.error(`Error checking whitelist status: ${error}`);
attempts++;
if (attempts < maxAttempts) {
await new Promise((resolve) => setTimeout(resolve, waitTime));
}
}
}
}
```
# SDKs
Source: https://docs.sophon.xyz/build/interact/sdks
This section will explain how to use popular SDKs with Sophon and provide all the relevant external links
<Warning>
This SDK guide is retained for legacy Sophon v1 deployments. Do not use it to
start a new production deployment on the chain.
</Warning>
**Sophon** is compatible with ZKsync Era SDKs, providing developers with powerful tools to build their applications. These SDKs offer features like enhanced scalability, security, and improved user experience through **Paymaster** support and **Account Abstraction**.
<Tip>
For detailed documentation and guides, visit [ZKsync's SDK Documentation](https://sdk.zksync.io/).
</Tip>
## JavaScript/TypeScript
<CardGroup>
<Card title="Ethers" icon="plug" href="https://sdk.zksync.io/js/ethers">
Recommended SDK for Ethers.js integration, supporting both v5 and v6. Perfect for existing Ethereum projects.
</Card>
<Card title="Viem" icon="bolt" href="https://viem.sh/zksync">
Modern TypeScript-first Ethereum library with excellent developer experience and type safety.
</Card>
<Card title="Web3.js" icon="code" href="https://sdk.zksync.io/js/web3js">
Popular Web3 library integration for developers familiar with the Web3.js ecosystem.
</Card>
</CardGroup>
<Note>
To understand better how to use our Paymaster for contract interactions, check our detailed **viem & wagmi with Sophon** [page](/build/interact/viem-wagmi).
</Note>
## Other Languages
<CardGroup>
<Card title="Go" icon="golang" href="https://sdk.zksync.io/go">
Full-featured SDK for Go developers with comprehensive blockchain integration capabilities.
</Card>
<Card title="Python" icon="python" href="https://sdk.zksync.io/python">
Python integration for blockchain development, perfect for data-driven applications.
</Card>
<Card title="Java" icon="java" href="https://sdk.zksync.io/java">
Enterprise-grade Java SDK for building robust blockchain applications.
</Card>
<Card title="Swift" icon="swift" href="https://sdk.zksync.io/swift">
Native iOS development support for building mobile blockchain applications.
</Card>
<Card title="Rust" icon="rust" href="https://sdk.zksync.io/rust">
Systems programming SDK with Rust for high-performance blockchain applications.
</Card>
</CardGroup>
# Tenderly
Source: https://docs.sophon.xyz/build/interact/tenderly
<Warning>
This integration guide is retained for legacy Sophon v1 deployments. Verify any
service endpoint directly before relying on it during the chain wind-down.
</Warning>
## Overview
[Tenderly](https://tenderly.co/) has fully integrated with Sophon, providing developers with a suite of tools to streamline smart contract development, testing, and monitoring. This integration enables seamless debugging, simulation, and infrastructure support fo프로젝트로 돌아가기