pub struct Contract { /* private fields */ }Implementations§
Source§impl Contract
impl Contract
pub fn from_address(web3: &CPCWeb3, address: &Address, abi_json: &[u8]) -> Self
pub fn event_sig(&self, event: &str) -> Option<H256>
Sourcepub fn deploy<'a>(web3: &'a CPCWeb3, abi_json: &'a [u8]) -> Deployer<'a>
pub fn deploy<'a>(web3: &'a CPCWeb3, abi_json: &'a [u8]) -> Deployer<'a>
Deploy smart contract e.g.
let bytecode = include_str!("../../fixtures/contracts/Metacoin.bin").trim_end();
let web3 = CPCWeb3::new("https://civilian.cpchain.io").unwrap();
let account = load_account();
assert_eq!(
account.address.to_checksum(),
"0x6CBea203F4061855247cea3843E2e5957C4CD428"
);
let balance = web3.balance(&account.address).await.unwrap();
println!("balance: {:?}", balance);
let c = Contract::deploy(
&web3,
include_bytes!("../../fixtures/contracts/Metacoin.abi"),
)
.options(Options::with(|opt| {
opt.value = Some(0.into());
opt.gas_price = Some((180_000_000_000 as u64).into());
opt.gas = Some(300_000.into());
}))
.sign_with_key_and_execute(bytecode, (), &account, 337.into())
.await
.unwrap();
println!("Address: {:?}", c.address());Sourcepub fn query<R, A, B, P>(
&self,
func: &str,
params: P,
from: A,
options: Options,
block: B,
) -> impl Future<Output = Result<R>> + '_
pub fn query<R, A, B, P>( &self, func: &str, params: P, from: A, options: Options, block: B, ) -> impl Future<Output = Result<R>> + '_
Call query methods of the smart contract e.g.
let web3 = CPCWeb3::new("https://civilian.cpchain.io").unwrap();
let account = load_account();
let c = Contract::from_address(
&web3,
&Address::from_str("0x8b3b22339466a3c8fd9b78c309aebfbf0bb95a9a").unwrap(),
include_bytes!("../../fixtures/contracts/Metacoin.abi"),
);
let r = c.query(
"getBalance",
(account.address.h160,),
None,
Options::default(),
None,
);
let balance: U256 = r.await.unwrap();
println!("balance: {:?}", balance);Sourcepub async fn signed_call(
&self,
web3: &CPCWeb3,
chain_id: u32,
func: &str,
params: impl Tokenize,
options: Options,
account: &Account,
) -> Result<H256>
pub async fn signed_call( &self, web3: &CPCWeb3, chain_id: u32, func: &str, params: impl Tokenize, options: Options, account: &Account, ) -> Result<H256>
Call functions of this contract
pub async fn logs( &self, web3: &CPCWeb3, event_name: &str, from_block: Option<u64>, to_block: Option<u64>, ) -> Result<Vec<Log>, StdError>
pub async fn events( &self, web3: &CPCWeb3, event_name: &str, from_block: Option<u64>, to_block: Option<u64>, ) -> Result<Vec<Event>, StdError>
pub fn parse_log( abi_json: &[u8], event_name: &str, log: &TransactionLog, ) -> Result<Event, StdError>
Auto Trait Implementations§
impl Freeze for Contract
impl !RefUnwindSafe for Contract
impl Send for Contract
impl Sync for Contract
impl Unpin for Contract
impl !UnwindSafe for Contract
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more