ethers.js/docs/v5/api/contract/contract-factory/README.md

94 lines
2.5 KiB
Markdown
Raw Permalink Normal View History

2020-06-09 23:56:58 -04:00
-----
2020-07-03 01:54:56 -04:00
Documentation: [html](https://docs.ethers.io/)
2020-06-09 23:56:58 -04:00
-----
ContractFactory
===============
Creating Instances
------------------
#### **new ***ethers* . **ContractFactory**( interface , bydecode [ , signer ] )
#### *ContractFactory* . **fromSolidity**( compilerOutput [ , signer ] ) => *[ContractFactory](/v5/api/contract/contract-factory/)*
#### *contractFactory* . **connect**( signer ) => *[Contract](/v5/api/contract/contract/)*
Properties
----------
#### *contractFactory* . **interface** => *[Interface](/v5/api/utils/abi/interface/)*
#### *contractFactory* . **bytecode** => *string< [DataHexString](/v5/api/utils/bytes/#DataHexString) >*
#### *contractFactory* . **signer** => *[Signer](/v5/api/signer/#Signer)*
Methods
-------
#### *contractFactory* . **attach**( address ) => *[Contract](/v5/api/contract/contract/)*
2020-06-12 03:38:55 -04:00
Return an instance of a [Contract](/v5/api/contract/contract/) attched to *address*. This is the same as using the [Contract constructor](/v5/api/contract/contract/#Contract--creating) with *address* and this the the *interface* and *signerOrProvider* passed in when creating the ContractFactory.
2020-06-09 23:56:58 -04:00
#### *contractFactory* . **getDeployTransaction**( ...args ) => *[UnsignedTransaction](/v5/api/utils/transactions/#UnsignedTransaction)*
Returns the unsigned transaction which would deploy this Contract with *args* passed to the Contract's constructor.
#### *contractFactory* . **deploy**( ...args ) => *Promise< [Contract](/v5/api/contract/contract/) >*
2020-07-03 01:54:56 -04:00
Uses the signer to deploy the Contract with *args* passed into the constructor and retruns a Contract which is attached to the address where this contract **will** be deployed once the transaction is mined.
2020-06-09 23:56:58 -04:00
2020-07-03 01:54:56 -04:00
The transaction can be found at `contract.deployTransaction`, and no interactions should be made until the transaction is mined.
2020-06-09 23:56:58 -04:00
```
// <hide>
const signer = ethers.LocalSigner();
const ContractFactory = ethers.ContractFactory;
// </hide>
// If your contract constructor requires parameters, the ABI
// must include the constructor
const abi = [
"constructor(address owner, uint256 initialValue)"
];
const factory = new ContractFactory(abi, bytecode, signer)
const contract = await factory.deploy("ricmoo.eth", 42);
// The address is available immediately, but the contract
// is NOT deployed yet
contract.address
//!
// The transaction that the signer sent to deploy
contract.deployTransaction
//!
// Wait until the transaction is mined
contract.deployTransaction.wait()
//!
2020-07-03 01:54:56 -04:00
// Now the contract is safe to interact with
2020-06-09 23:56:58 -04:00
contract.value()
//!
```