Is it possible to connect 2 cannisters from different projects/smart contracts

I have project 1, created with dfx new project1 and project2 created the same way, is there a way to make the canister in project2 make api calls to the canister in project1? I want project1 to be dedicated for backend with Motoko, and then project2 to be dedicated for React frontend, I know each project comes with its own backend and frontend, but in this case is it possible to connect canisters in seperate projects?

Yes, no problem. You simply have to have the right canister IDs to call. You can also merge the two projects into one to make that easier

1 Like

Okay, right now I only know how to connect to a backend canister from a frontend canister in the same project like this import { mybackend_canister } from "../../../declarations/mybackend_canister/index";. So for the case of canisters in different projects how exactly do I go about it? Or maybe you can direct me to some documentation on this and aslo about merging two projects into one. Thank you.

You can copy over the declarations, or just use an ugly file path that will only work on your machine. If you really want a lot of interoperability, I’d suggest putting both in the same project so you have all declarations in the same place.

You can also somehow create an actor from just a canister ID, but then you won’t have as nice of an interface

1 Like

Okay, let me see how I can impliment that. Thank you.