Skip to main content

call

extern fn call(contract: felt252, function_name: felt252, calldata: @Array::<felt252>) -> Result::<(Array::<felt252>), RevertedTransaction> nopanic;

Calls a deployed contract. Unlike invoke, it does not mutate the blockchain state.

  • contract - deployed contract address
  • function_name - the name of the function you wish to call, this is the Cairo short string which can be at most 31-characters long.
  • calldata - arguments to the target function
Example
use array::ArrayTrait;
use result::ResultTrait;

#[test]
fn test_call() {
let mut calldata = ArrayTrait::new();
calldata.append(3);
calldata.append(2);
calldata.append(5);
let return_data2 = call(deployed_contract_address, 'foo', @calldata).unwrap();
assert(*return_data2.at(0_u32) == 25, 'check call result');
}

You can find more examples here.