I have the following method in my contract:
#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
pub struct MyContract {
...,
}
#[near_bindgen]
impl MyContract {
...
pub fn is_account_whitelisted(account_id: &AccountId) -> bool {
Self::account_task_ordinals_map().contains_key(account_id)
}
fn account_task_ordinals_map() -> LookupMap<AccountId, Option<u32>> {
LookupMap::new(b"o".to_vec())
}
...
}
is_account_whitelisted is intended to be used as a view method. I then later use it from near-api-js in the following way:
window.contract = await near.loadContract(nearConfig.contractName, {
viewMethods: ['is_account_whitelisted', ...],
changeMethods: [...],
sender: window.walletAccount.getAccountId()
});
...
window.contract.is_account_whitelisted({'account_id': window.walletAccount.getAccountId()}).then(m => console.log(m));
and it fails with
...
FunctionCallError(HostError(ProhibitedInView { method_name: "attached_deposit" })).
{
"error": "wasm execution failed with error: FunctionCallError(HostError(ProhibitedInView { method_name: \"attached_deposit\" }))",
...
Do I need to annotate the method in some way, am I not calling it right, or is there something that I use in the method that causes the call to the attached_deposit?
Thanks to the Evgeny's comment, I found out that presently a method is only considered a view method if it has a immutable self as the first argument. Here's the link to the relevant code in near-sdk-rs:
https://github.com/near/near-sdk-rs/blob/18b8f8f3b672bfb422ff83a5138395f7e24dd70d/near-sdk-core/src/info_extractor/attr_sig_info.rs#L109
It is likely to be fixed soon, but in the meantime the way to address it is to add the immutable self as the first argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With