Post
Share your knowledge.
How to call a function from another Move contract?
I've deployed a contract with an address 0x3df... and a public function 'coll'. Now, I'm trying to write another contract that calls this 'coll' function, but I'm getting an error saying 'use 0x3df...::coll; use is invalid. Unbound module'. I've seen suggestions about using a dependencies file but I'm not sure how to implement this properly. What steps should I take to resolve the error and successfully call the function?
- Move CLI
- Move
Answers
2To call a function from another Move contract, you need the source code of the first package. If it's available locally or on GitHub, you should add it in the Move.toml file as a local dependency. When you published your first package, a Move.lock file was created which contains the package's published address. This address will be used in your other project that depends on this published package. Here's a resource for setting up dependencies: Move Book on Manifest.
Make sure you have set up your local dependencies correctly. Instead of directly using 'use 0x3df...::coll;', you should ensure that the first package is properly integrated. The error you're seeing generally suggests that the module isn't recognized because it's not correctly linked in your dependencies.
Do you know the answer?
Please log in and share it.
Move is an executable bytecode language used to implement custom transactions and smart contracts.