or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

contract-deployment.mdcontract-interaction.mdevent-management.mdindex.mdtransaction-handling.md
tile.json

contract-deployment.mddocs/

Contract Deployment

Contract deployment functionality through ContractFactory. Enables deploying new contract instances and managing deployment transactions with constructor parameter encoding and deployment tracking.

Capabilities

ContractFactory Class

Factory class for deploying new contract instances from bytecode and ABI.

/**
 * Factory for deploying new contract instances
 */
class ContractFactory {
  /** Contract ABI interface for constructor and method encoding */
  readonly interface: Interface;
  /** Contract bytecode for deployment */
  readonly bytecode: string;
  /** Signer for deployment transactions */
  readonly signer: Signer;
}

Usage Examples:

import { ContractFactory } from "@ethersproject/contracts";
import { Wallet } from "@ethersproject/wallet";
import { JsonRpcProvider } from "@ethersproject/providers";

const provider = new JsonRpcProvider("https://mainnet.infura.io/v3/YOUR_KEY");
const wallet = new Wallet("YOUR_PRIVATE_KEY", provider);

// Contract ABI and bytecode
const abi = [
  "constructor(string name, string symbol)",
  "function name() view returns (string)",
  "function symbol() view returns (string)"
];
const bytecode = "0x608060405234801561001057600080fd5b50..."; // Contract bytecode

// Create factory
const factory = new ContractFactory(abi, bytecode, wallet);

// Deploy contract
const contract = await factory.deploy("MyToken", "MTK");
await contract.deployed();

console.log("Contract deployed at:", contract.address);

ContractFactory Constructor

Creates a new ContractFactory instance with the specified ABI, bytecode, and signer.

/**
 * Create a new ContractFactory instance
 * @param contractInterface - Contract ABI specification
 * @param bytecode - Contract bytecode (hex string, bytes, or compiler output object)
 * @param signer - Signer for deployment transactions (optional)
 */
constructor(
  contractInterface: ContractInterface,
  bytecode: BytesLike | { object: string },
  signer?: Signer
);

Contract Deployment

Deploy a new contract instance with constructor parameters.

/**
 * Deploy a new contract instance
 * @param args - Constructor arguments followed by optional transaction overrides
 * @returns Promise resolving to deployed Contract instance
 */
deploy(...args: Array<any>): Promise<Contract>;

Usage Examples:

// Deploy without constructor parameters
const simpleContract = await factory.deploy();

// Deploy with constructor parameters
const tokenContract = await factory.deploy("MyToken", "MTK", 18);

// Deploy with constructor parameters and transaction overrides
const contractWithOverrides = await factory.deploy(
  "MyToken", 
  "MTK", 
  { 
    gasLimit: 2000000, 
    gasPrice: ethers.utils.parseUnits("20", "gwei") 
  }
);

// Wait for deployment confirmation
await contractWithOverrides.deployed();

Deployment Transaction

Get the deployment transaction without sending it.

/**
 * Get deployment transaction object without sending
 * @param args - Constructor arguments followed by optional transaction overrides
 * @returns Transaction request object ready for signing/sending
 */
getDeployTransaction(...args: Array<any>): TransactionRequest;

Usage Examples:

// Get deployment transaction
const deployTx = factory.getDeployTransaction("MyToken", "MTK");

// Inspect transaction before sending
console.log("Deployment data:", deployTx.data);
console.log("Estimated gas:", await wallet.estimateGas(deployTx));

// Send manually
const sentTx = await wallet.sendTransaction(deployTx);
await sentTx.wait();

Factory Connection Management

Connect the factory to a different signer or attach to an existing contract.

/**
 * Attach factory to existing deployed contract
 * @param address - Address of deployed contract
 * @returns Contract instance at the specified address
 */
attach(address: string): Contract;

/**
 * Connect factory to different signer
 * @param signer - New signer for deployment transactions
 * @returns New ContractFactory instance with the specified signer
 */
connect(signer: Signer): ContractFactory;

Usage Examples:

// Attach to existing contract
const existingContract = factory.attach("0x...");

// Connect to different signer
const newWallet = new Wallet("DIFFERENT_PRIVATE_KEY", provider);
const factoryWithNewSigner = factory.connect(newWallet);

Static Factory Methods

Utility methods for creating ContractFactory instances and managing contracts.

/**
 * Create ContractFactory from Solidity compiler output
 * @param compilerOutput - Solidity compiler output (JSON)
 * @param signer - Signer for deployment transactions (optional)
 * @returns ContractFactory instance
 */
static fromSolidity(compilerOutput: any, signer?: Signer): ContractFactory;

/**
 * Create Interface from contract ABI
 * @param contractInterface - Contract ABI specification
 * @returns Interface object for ABI operations
 */
static getInterface(contractInterface: ContractInterface): Interface;

/**
 * Calculate contract address from deployment transaction
 * @param tx - Transaction with from address and nonce
 * @returns Calculated contract address
 */
static getContractAddress(tx: { 
  from: string; 
  nonce: BytesLike | BigNumber | number; 
}): string;

/**
 * Create Contract instance
 * @param address - Contract address
 * @param contractInterface - Contract ABI specification
 * @param signer - Signer for transactions (optional)
 * @returns Contract instance
 */
static getContract(
  address: string, 
  contractInterface: ContractInterface, 
  signer?: Signer
): Contract;

Usage Examples:

// Create factory from Solidity compiler output
const compilerOutput = {
  abi: [...],
  bytecode: "0x608060405234801561001057600080fd5b50...",
  // ... other compiler output fields
};
const factoryFromSolidity = ContractFactory.fromSolidity(compilerOutput, wallet);

// Calculate contract address before deployment
const futureAddress = ContractFactory.getContractAddress({
  from: wallet.address,
  nonce: await wallet.getTransactionCount()
});
console.log("Contract will be deployed at:", futureAddress);

// Create contract instance directly
const contract = ContractFactory.getContract("0x...", abi, wallet);