Closed wlsgh199 closed 2 years ago
ethabi의 functions_by_name를 사용하여 해결하였습니다
let contract: web3::ethabi::Contract = serde_json::from_slice(&ABI).unwrap();
let func = contract.functions_by_name("encodeArgs").unwrap();
let func_data =func[1].encode_input(&[Token::String(_orderid.to_owned()), Token::Array(routes.to_owned()) ,Token::Uint(U256::from(100_u128))]).unwrap();
let call_req = web3::types::CallRequest{
from:Some(H160::from_str(from).unwrap()),
to : Some(ca),
data: Some(Bytes(func_data.into())) ,
..Default::default()
};
let result_bytes = web3.eth().call(call_req, None).await.unwrap();
let decode = func[1].decode_output(&result_bytes.0).unwrap();
Hello.
I have two functions as follows.
Overloading
function encodeArgs(string memory orderId, RoutePair[] memory routes) public view returns(bytes32[] memory data) { ...~~ }
function encodeArgs(string memory orderId, RoutePair[] memory routes, uint256 test_uint) public view returns(bytes32[] memory data){ ...~~ }
2 arg is Ok 3 arg is Error
main.rs
let contract = web3::contract::Contract::from_json(web3.eth(), Address::from_slice(ca), &ABI).unwrap();
let result: Vec = contract.query("encodeArgs", (Token::String(_orderid), Token::Array(routes),Token::Uint(U256::from(100_u128))), None, web3::contract::Options::default(), None).await.unwrap();