How to call a view function in Aptos

Hi everyone,
I am using the Aptos Rest API to execute a view function of a module.
However, it always return 400 error.
Here’s sample module on Testnet.

Aptos Code: return number 2.

#[view]
public fun ret_text_v3(): u64{
2
}

I used the rest API to submit the request : Aptos REST API
API URL: https://fullnode.testnet.aptoslabs.com/v1
/view
API Params:

{
function: “0xf0f627544963910cf55a51d4fd87973e3a60b45ef2173db8b45362631e7ee668::swap::ret_text_v3”,
arguments: ,
type_arguments:
};

Return: 400 Bad Request

{
“message”: “PartialVMError with status INVALID_MAIN_FUNCTION_SIGNATURE and message function not marked as view function”,
“error_code”: “invalid_input”,
“vm_error_code”: null
}

Can everyone help with the root cause of it?
Thank you so much

22 Likes

Helpful info!

7 Likes

Try chat gpt

6 Likes

beautiful lake

5 Likes

Thanks bro, helpfull info

4 Likes

Good to know mate

5 Likes

Important info, thank’s so much! :grinning:

6 Likes

thanks bro, great info

3 Likes

Helpful info!

4 Likes

thanks for the info

3 Likes

thanks for the guide

3 Likes

Thanks for helpfull info

2 Likes