or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

contract-deployment.mdcontract-factories.mdcontract-instances.mdindex.mdprovider-access.mdsigner-management.md

contract-deployment.mddocs/

0

# Contract Deployment

1

2

Deploy contracts directly from project artifacts with constructor arguments, library linking, and deployment options.

3

4

## Capabilities

5

6

### Deploy Contract

7

8

Deploys a contract from your Hardhat project artifacts.

9

10

```typescript { .api }

11

/**

12

* Deploy a contract from project artifacts

13

* @param name - Contract name or fully qualified name (e.g., "contracts/Counter.sol:Counter")

14

* @param signerOrOptions - Signer to deploy with or deployment options

15

* @returns Promise resolving to deployed contract instance

16

*/

17

function deployContract(

18

name: string,

19

signerOrOptions?: ethers.Signer | DeployContractOptions

20

): Promise<ethers.Contract>;

21

22

/**

23

* Deploy a contract with constructor arguments

24

* @param name - Contract name or fully qualified name

25

* @param args - Constructor arguments array

26

* @param signerOrOptions - Signer to deploy with or deployment options

27

* @returns Promise resolving to deployed contract instance

28

*/

29

function deployContract(

30

name: string,

31

args: any[],

32

signerOrOptions?: ethers.Signer | DeployContractOptions

33

): Promise<ethers.Contract>;

34

35

interface DeployContractOptions extends FactoryOptions, ethers.Overrides {

36

signer?: ethers.Signer;

37

libraries?: Libraries;

38

// Plus all ethers.Overrides properties like gasPrice, gasLimit, etc.

39

}

40

41

interface Libraries {

42

[libraryName: string]: string | ethers.Addressable;

43

}

44

```

45

46

**Usage Examples:**

47

48

```typescript

49

import { network } from "hardhat";

50

51

const { ethers } = await network.connect();

52

53

// Simple deployment

54

const counter = await ethers.deployContract("Counter");

55

56

// Deployment with constructor arguments

57

const token = await ethers.deployContract("Token", ["MyToken", "MTK", 1000000]);

58

59

// Deployment with specific signer

60

const [, deployer] = await ethers.getSigners();

61

const counter = await ethers.deployContract("Counter", [], deployer);

62

63

// Deployment with library linking

64

const mathLibrary = await ethers.deployContract("MathLib");

65

const calculator = await ethers.deployContract("Calculator", {

66

libraries: {

67

MathLib: mathLibrary.address,

68

},

69

});

70

71

// Deployment with gas options

72

const counter = await ethers.deployContract("Counter", [], {

73

gasPrice: ethers.parseUnits("20", "gwei"),

74

gasLimit: 500000,

75

});

76

77

// Fully qualified contract name for contracts with same names

78

const counter = await ethers.deployContract("contracts/v1/Counter.sol:Counter");

79

```

80

81

### Library Linking

82

83

When deploying contracts that depend on external libraries, you must provide their addresses.

84

85

```typescript

86

// Deploy library first

87

const safemath = await ethers.deployContract("SafeMath");

88

89

// Link library when deploying contract

90

const calculator = await ethers.deployContract("Calculator", {

91

libraries: {

92

SafeMath: safemath.address,

93

// Can also use string addresses

94

"contracts/utils/Utils.sol:Utils": "0x1234...abcd",

95

},

96

});

97

```

98

99

### Deployment Options

100

101

The `DeployContractOptions` interface extends both `FactoryOptions` and `ethers.Overrides`, allowing you to specify:

102

103

- **Signer**: Which account to deploy from

104

- **Libraries**: Library addresses for linking

105

- **Gas settings**: gasPrice, gasLimit, maxFeePerGas, etc.

106

- **Value**: ETH to send with deployment

107

- **Nonce**: Specific transaction nonce

108

109

```typescript

110

const options: DeployContractOptions = {

111

signer: await ethers.getSigner("0x1234..."),

112

libraries: {

113

MyLib: "0x5678...",

114

},

115

gasPrice: ethers.parseUnits("25", "gwei"),

116

gasLimit: 1000000,

117

value: ethers.parseEther("1.0"), // Send 1 ETH with deployment

118

};

119

120

const contract = await ethers.deployContract("MyContract", [arg1, arg2], options);

121

```