Cross-Contract
A cross-contract invocation is a powerful (yet expensive) kind of contract interaction. A contract invocation is similar to starting a new process because the code that runs will be in a separate address space, meaning that they do not share any data other than what was passed in the invocation. While a contract invocation typically transfers control to a different contract, it is possible to transfer control to the currently running contract. Regardless of whether the contract that receives control is a different contract or the currently running contract, the value returned by get_invoking_contract will be the previous value of get_current_contract. A contract invocation can only access the public methods of a contract.
One public function is an exception: a contract's __constructor is invoked by the host at deployment, rather than by another contract. For example, the token example contract sets its admin and metadata in a constructor:
#[contractimpl]
impl Token {
pub fn __constructor(e: Env, admin: Address, decimal: u32, name: String, symbol: String) {
So instead of being invoked like other functions, its arguments are passed to deploy_v2, which deploys the contract and runs its constructor in the same invocation:
e.deployer()
.with_current_contract(salt)
.deploy_v2(token_wasm_hash, (admin, decimal, name, symbol))
In tests, the same arguments are passed to register:
e.register(Token {}, (admin, decimal, name, symbol))
For calling a contract's other functions, see Making cross-contract calls.