extern crate env_logger; extern crate rustc_hex; extern crate web3_etz; use web3_etz::contract::{Contract, Options}; use web3_etz::futures::Future; use web3_etz::types::{Address, U256}; fn main() { env_logger::init(); let (eloop, http) = web3_etz::transports::Http::new("http://localhost:8545").unwrap(); // run the event loop in the background eloop.into_remote(); let web3_etz = web3_etz::Web3::new(http); let my_account: Address = "d028d24f16a8893bd078259d413372ac01580769".parse().unwrap(); // Get the contract bytecode for instance from Solidity compiler let bytecode = include_str!("./contract_token.code"); // Deploying a contract let contract = Contract::deploy(web3_etz.eth(), include_bytes!("../src/contract/res/token.json")) .unwrap() .confirmations(0) .options(Options::with(|opt| { opt.value = Some(5.into()); opt.gas_price = Some(5.into()); opt.gas = Some(1_000_000.into()); })) .execute( bytecode, (U256::from(1_000_000), "My Token".to_owned(), 3u64, "MT".to_owned()), my_account, ) .expect("Correct parameters are passed to the constructor.") .wait() .unwrap(); let result = contract.query("balanceOf", (my_account,), None, Options::default(), None); let balance_of: U256 = result.wait().unwrap(); assert_eq!(balance_of, 1_000_000.into()); // Accessing existing contract let contract_address = contract.address(); let contract = Contract::from_json( web3_etz.eth(), contract_address, include_bytes!("../src/contract/res/token.json"), ) .unwrap(); let result = contract.query("balanceOf", (my_account,), None, Options::default(), None); let balance_of: U256 = result.wait().unwrap(); assert_eq!(balance_of, 1_000_000.into()); }