How can I call a function belonging to one package and call from another package

How can I call a function belonging to one package and call from another package syntax-wise?

2 Likes

First you need to include the package as a dependency in your Move.toml file - as you do for Sui basically. You can do it either by supplying a local dir to load the contract from or a github link.

Let’s say that other package is called someotherpackage. Then,

# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
# someotherpackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" }

# For local dependencies use `local = path`. Path is relative to the package root
# someotherpackage = { local = "../path/to" }

After including the dependency in your Move.toml, you can import the module you want to use someotherpackage::module_x and can call (public only) functions from the other package as such module_x::function_y.

Then whenever you sui move build, instead of pulling the dependencies for Sui and STD only, it will also pull the dependencies for someotherpackage.

4 Likes