ContractFactory
To deploy a Contract, additional information is needed that is not available on a Contract object itself.
Mainly, the bytecode (more specifically the initcode) of a contract is required.
The Contract Factory sends special transactions to completly contract deployment. Before the main contract creation transaction, there are several transactions that have to be executed:
FileCreateTransaction
- including a customData field with fileChunk and fileKey properties. Returns fileId as property in customData of transaction's response.n
x FileAppendTransaction
- in Hedera ecosystem, each transaction has maximum size of6KB
, so if there is a contract with a bigger size, it has to be separated into chunks. Each chunk must be uploaded viaFileAppendTransaction
with customData containing fileId and fileChunk.ContractCreateTransaction
- actually deploying the contract, the transaction includes gasLimit and customData with bytecodeFileId
The Contract Factory executes the defined transactions under the hood and the complexity is hidden from the hethers
users.
Creating Instances
new hethers.ContractFactory( interface , bytecode [ , signer ] )
new hethers.ContractFactory( interface , bytecode [ , signer ] )
Creates a new instance of a ContractFactory for the contract described by the interface and bytecode initcode.
ContractFactory.fromSolidity( compilerOutput [ , signer ] )
⇒ ContractFactory
ContractFactory.fromSolidity( compilerOutput [ , signer ] )
⇒ ContractFactoryConsumes the output of the Solidity compiler, extracting the ABI and bytecode from it, allowing for the various formats the solc compiler has emitted over its life.
contractFactory.connect( signer )
⇒ ContractFactory
contractFactory.connect( signer )
⇒ ContractFactoryReturns a new instance of the ContractFactory with the same interface and bytecode, but with a different signer.
Properties
contractFactory.interface
⇒ Interface
contractFactory.interface
⇒ InterfaceThe Contract interface.
contractFactory.bytecode ⇒ string< DataHexString >
The bytecode (i.e. initcode) that this ContractFactory will use to deploy the Contract.
contractFactory.signer ⇒ Signer
The Signer (if any) this ContractFactory will use to deploy instances of the Contract.
Methods
contractFactory.attach( address )
⇒ Contract
contractFactory.attach( address )
⇒ ContractReturn an instance of a Contract attached to address. This is the same as using the Contract constructor with address and this the interface and signerOrProvider passed in when creating the ContractFactory.
contractFactory.getDeployTransaction( ...args [ , overrides ] )
⇒ UnsignedTransaction
contractFactory.getDeployTransaction( ...args [ , overrides ] )
⇒ UnsignedTransactionReturns the unsigned transaction which would deploy this Contract with args passed to the Contract's constructor.
If the optional overrides is specified, they can be used to override the endowment value
and transactiongasLimit.
contractFactory.deploy( ...args [ , overrides ] )
⇒ Promise< Contract >
contractFactory.deploy( ...args [ , overrides ] )
⇒ Promise< Contract >Uses the signer to deploy the Contract with args passed into the constructor and returns a Contract which is attached to the address where this contract will be deployed once the transaction is mined.
The transaction can be found at contract.deployTransaction
, and no interactions should be made until the transaction is mined.
If the optional overrides is specified, they can be used to override the endowment value
and transaction gasLimit
.
Deploying a Contract
Last updated