/// Sends a transaction which does not change blockchain state, usually to get information.
Sends a transaction which does not change blockchain state, usually to get information.
Sends a transaction which does not change blockchain state usually to get information .
pub async fn contract_call(
        &self,
        contract_address: Address,
        sig: &str,
        tokens: &[Token],
        own_address: Address,
    ) -> Result<Vec<u8>, Web3Error> {
        let our_balance = self.eth_get_balance(own_address).await?;
        let nonce = self.eth_get_transaction_count(own_address).await?;
        let payload = encode_call(sig, tokens)?;
        let gas_price: Uint256 = 1u8.into();
        // Geth represents gas as a u64 it will truncate leading zeros but not take
        // a value larger than u64::MAX, likewise the command will fail if we can't
        // actually pay that fee. This operation maximizes the info we can get
        let gas_limit = min((u64::MAX - 1).into(), our_balance);
        let transaction = TransactionRequest {
            from: Some(own_address),
            to: contract_address,
            nonce: Some(UnpaddedHex(nonce)),
            gas: Some(gas_limit.into()),
            gas_price: Some(UnpaddedHex(gas_price)),
            value: Some(UnpaddedHex(0u64.into())),
            data: Some(Data(payload)),
        };
        let bytes = match self.eth_call(transaction).await {
            Ok(val) => val,
            Err(e) => return Err(e),
        };
        Ok(bytes.0)
    }
pub async fn contract_call ( & self , contract_address : Address , sig : & str , tokens : & [ Token ] , own_address : Address , ) -> Result < Vec < u8 > , Web3Error > { let our_balance = self . eth_get_balance ( own_address ) . await ? ; let nonce = self . eth_get_transaction_count ( own_address ) . await ? ; let payload = encode_call ( sig , tokens ) ? ; let gas_price : Uint256 = 1u8 . into ( ) ; // Geth represents gas as a u64 it will truncate leading zeros but not take // a value larger than u64::MAX, likewise the command will fail if we can't // actually pay that fee. This operation maximizes the info we can get let gas_limit = min ( ( u64 :: MAX - 1 ) . into ( ) , our_balance ) ; let transaction = TransactionRequest { from : Some ( own_address ) , to : contract_address , nonce : Some ( UnpaddedHex ( nonce ) ) , gas : Some ( gas_limit . into ( ) ) , gas_price : Some ( UnpaddedHex ( gas_price ) ) , value : Some ( UnpaddedHex ( 0u64 . into ( ) ) ) , data : Some ( Data ( payload ) ) , } ; let bytes = match self . eth_call ( transaction ) . await { Ok ( val ) => val , Err ( e ) => return Err ( e ) , } ; Ok ( bytes . 0 ) }
Sends a transaction which does not change blockchain state, usually to get information.
Sends a transaction which does not change blockchain state usually to get information .
&self
contract_address
Address
sig
&str
tokens
&[Token]
own_address
Address