Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feat(ContractDeployer): add tx builder methods #1289

Merged
merged 1 commit into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@

### Unreleased

- Added tx builder methods to `ContractFactory`
[#1289](https://github.com/gakonst/ethers-rs/pull/1289)
- Relax Clone requirements when Arc<Middleware> is used
[#1183](https://github.com/gakonst/ethers-rs/pull/1183)
- Add `EventStream::select` to combine streams with different event types
Expand Down
52 changes: 50 additions & 2 deletions ethers-contract/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::marker::PhantomData;
use ethers_core::{
abi::{Abi, Token, Tokenize},
types::{
transaction::eip2718::TypedTransaction, BlockNumber, Bytes, TransactionReceipt,
TransactionRequest,
transaction::eip2718::TypedTransaction, Address, BlockNumber, Bytes, NameOrAddress,
TransactionReceipt, TransactionRequest, U256, U64,
},
};
use ethers_providers::Middleware;
Expand Down Expand Up @@ -59,6 +59,54 @@ impl<M: Middleware, C: From<Contract<M>>> ContractDeployer<M, C> {
self
}

/// Sets the `from` field in the deploy transaction to the provided value
pub fn from<T: Into<Address>>(mut self, from: T) -> Self {
self.deployer.tx.set_from(from.into());
self
}

/// Sets the `to` field in the deploy transaction to the provided value
pub fn to<T: Into<NameOrAddress>>(mut self, to: T) -> Self {
self.deployer.tx.set_to(to.into());
self
}

/// Sets the `gas` field in the deploy transaction to the provided value
pub fn gas<T: Into<U256>>(mut self, gas: T) -> Self {
self.deployer.tx.set_gas(gas.into());
self
}

/// Sets the `gas_price` field in the deploy transaction to the provided value
pub fn gas_price<T: Into<U256>>(mut self, gas_price: T) -> Self {
self.deployer.tx.set_gas_price(gas_price.into());
self
}

/// Sets the `value` field in the deploy transaction to the provided value
pub fn value<T: Into<U256>>(mut self, value: T) -> Self {
self.deployer.tx.set_value(value.into());
self
}

/// Sets the `data` field in the deploy transaction to the provided value
pub fn data<T: Into<Bytes>>(mut self, data: T) -> Self {
self.deployer.tx.set_data(data.into());
self
}

/// Sets the `nonce` field in the deploy transaction to the provided value
pub fn nonce<T: Into<U256>>(mut self, nonce: T) -> Self {
self.deployer.tx.set_nonce(nonce.into());
self
}

/// Sets the `chain_id` field in the deploy transaction to the provided value
pub fn chain_id<T: Into<U64>>(mut self, chain_id: T) -> Self {
self.deployer.tx.set_chain_id(chain_id.into());
self
}

/// Dry runs the deployment of the contract
///
/// Note: this function _does not_ send a transaction from your account
Expand Down