Go API

BaseDeployer

Deploys smart contracts and accounts

The BaseDeployer facilitates the deployment of smart contracts and smart accounts on the ZKsync Era network. It provides methods to deploy contracts using both the CREATE and CREATE2 methods, ensuring flexibility and security in contract deployment.

Init

Creates an instance of BaseDeployer based on provided AdapterL2.

func NewBaseDeployer(adapter *AdapterL2) *BaseDeployer

Deploy

Deploys smart contract using CREATE2 method.

Inputs

ParameterTypeDescription
auth*TransactOpts (optional)Transaction options.
txCreate2TransactionCREATE2 transaction parameters.
Deploy(auth *TransactOpts, tx Create2Transaction) (common.Hash, error)

Example

bytecode, err := os.ReadFile("Storage.zbin")
if err != nil {
    log.Panic(err)
}

//Deploy smart contract
hash, err := wallet.Deploy(nil, accounts.Create2Transaction{Bytecode: bytecode})
if err != nil {
    panic(err)
}
fmt.Println("Transaction: ", hash)

DeployAccount

Deploys smart account using CREATE2 method.

Inputs

ParameterTypeDescription
auth*TransactOpts (optional)Transaction options.
txCreate2TransactionCREATE2 transaction parameters.
DeployAccount(auth *TransactOpts, tx Create2Transaction) (common.Hash, error)

Example

# Crown token on testnet
TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F")

_, paymasterAbi, bytecode, err := utils.ReadStandardJson("Paymaster.json")
if err != nil {
    log.Panic(err)
}

// Encode paymaster constructor
constructor, err := paymasterAbi.Pack("", common.HexToAddress(TokenAddress))
if err != nil {
    log.Panic(err)
}

// Deploy paymaster contract
hash, err := wallet.DeployAccount(nil, accounts.Create2Transaction{Bytecode: bytecode, Calldata: constructor})
if err != nil {
    log.Panic(err)
}
if err != nil {
    log.Panic(err)
}
fmt.Println("Transaction: ", hash)

DeployAccountWithCreate

Deploys smart account using CREATE method.

Inputs

ParameterTypeDescription
auth*TransactOpts (optional)Transaction options.
txCreateTransactionCREATE transaction parameters.
DeployAccountWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error)

Example

# Crown token on testnet
TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F")

_, paymasterAbi, bytecode, err := utils.ReadStandardJson("Paymaster.json")
if err != nil {
    log.Panic(err)
}

constructor, err := paymasterAbi.Pack("", common.HexToAddress(TokenAddress))
if err != nil {
    log.Panic(err)
}

// Deploy paymaster contract
hash, err := wallet.DeployAccountWithCreate(nil, accounts.CreateTransaction{
    Bytecode: bytecode,
    Calldata: constructor,
})
if err != nil {
    log.Panic(err)
}
fmt.Println("Transaction: ", hash)

DeployWithCreate

Deploys smart contract using CREATE method.

Inputs

ParameterTypeDescription
auth*TransactOpts (optional)Transaction options.
txCreateTransactionCREATE transaction parameters.
DeployWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error)

Example

bytecode, err := os.ReadFile("Storage.zbin")
if err != nil {
    log.Panic(err)
}

//Deploy smart contract
hash, err := wallet.DeployWithCreate(nil, accounts.CreateTransaction{Bytecode: bytecode})
if err != nil {
    panic(err)
}
fmt.Println("Transaction: ", hash)

Made with ❤️ by the ZKsync Community