tomusdrw / rust-web3

Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library. ENS address: rust-web3.eth
MIT License
1.45k stars 465 forks source link

Passing bytes4 in params of contract.query resulting an Abi error: Invalid data. #615

Open lafbelmonte opened 2 years ago

lafbelmonte commented 2 years ago

I can't seem to pass bytes 4 in params of contract.query.

code:

let contract = Contract::from_json(
                                logs_worker_web3.eth(),
                                log.address,
                                include_bytes!("supports_interface_abi.json"),
                            )
                            .unwrap();

let supports_interface: bool = match contract
                                    .query(
                                        "supportsInterface",
                                        (Bytes::from("0x80ac58cd"),),
                                        None,
                                        Options::default(),
                                        None,
                                    )
                                    .await
                                {
                                    Ok(value) => {
                                        println!("{}", value);
                                        value
                                    }
                                    Err(error) => {
                                        eprintln!("{}", error);
                                        continue;
                                    }
                                };

abi:

[
    {
        "constant": true,
        "inputs": [
            {
                "internalType": "bytes4",
                "name": "interfaceId",
                "type": "bytes4"
            }
        ],
        "name": "supportsInterface",
        "outputs": [
            {
                "internalType": "bool",
                "name": "",
                "type": "bool"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    }
]

Result:

Abi error: Invalid data