4

Within a function, how do I call other functions?

pub fn process_a(ctx: Context<CreateItemA>) -> Result<()> {
   /// Do something things with item A here...

   /// Now call process_b?
   let returned_value = process_b("test"); <--- What is the proper syntax here?

   /// Do something with returned_value

   Ok(())
}

pub fn process_b(value: String) -> Result<String> {
   /// Do something with value here

   Ok("Some returned value")
}

I know I can call these one after another from client side but I was wondering if I can chain it all in one single call if possible on chain.

1 Answer 1

3

You want to look into Cross-Program Invocations which is the way to make programs interact with each other on Solana.

If you want a more practical and in-depth explication I can recommend watching this video by SolAndy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.