Deploy a contract to the chain. # Examples ```ignore let web3 = web3::Web3::new("http://127.0.0.1:8545").unwrap(); let account = web3.get_all_accounts().await.unwrap()[0]; let contract = include_bytes!("./../../contracts/artifacts/contracts/ERC20.sol/RustCoinToken.json").to_vec(); let tx_hash = web3.deploy(account, &contract).await; assert!(tx_hash.is_ok()); ```
(
&self,
owner: Address,
abi: &'a [u8],
nonce: Option<U256>,
)
| 30 | /// assert!(tx_hash.is_ok()); |
| 31 | /// ``` |
| 32 | pub async fn deploy<'a>( |
| 33 | &self, |
| 34 | owner: Address, |
| 35 | abi: &'a [u8], |
| 36 | nonce: Option<U256>, |
| 37 | ) -> Result<H256> { |
| 38 | let gas = U256::from(1_000_000); |
| 39 | let gas_price = U256::from(1_000_000); |
| 40 | let data: Bytes = abi.to_vec().into(); |
| 41 | let transaction_request = TransactionRequest { |
| 42 | from: Some(owner), |
| 43 | to: None, |
| 44 | value: Some(U256::zero()), |
| 45 | gas, |
| 46 | gas_price, |
| 47 | data: Some(data), |
| 48 | nonce, |
| 49 | r: None, |
| 50 | s: None, |
| 51 | }; |
| 52 | |
| 53 | self.send(transaction_request).await |
| 54 | } |
| 55 | |
| 56 | /// Get the contract code for an address |
| 57 | /// |