In the latest master of Ink! examples there is only one main contract, delegator, for understanding cross-contract calls. Unfortunately, there are no tests either for this system.

Cross-contract calling seems to rest on the ContractRef pattern where the ContractRefs are instantiated in the base contract's constructor.

    pub struct Delegator {
        /// Says which of `adder` or `subber` is currently in use.
        which: Which,
        /// The `accumulator` smart contract.
        accumulator: AccumulatorRef,
        /// The `adder` smart contract.
        adder: AdderRef,
        /// The `subber` smart contract.
        subber: SubberRef,


    impl Delegator {
        /// Instantiate a `delegator` contract with the given sub-contract codes.
        pub fn new(
            init_value: i32,
            version: u32,
            accumulator_code_hash: Hash,
            adder_code_hash: Hash,
            subber_code_hash: Hash,
        ) -> Self {
            let total_balance = Self::env().balance();
            let salt = version.to_le_bytes();
            let accumulator = AccumulatorRef::new(init_value)
                .endowment(total_balance / 4)
                .unwrap_or_else(|error| {
                        "failed at instantiating the Accumulator contract: {:?}",
            let adder = AdderRef::new(accumulator.clone())
                .endowment(total_balance / 4)
                .unwrap_or_else(|error| {
                    panic!("failed at instantiating the Adder contract: {:?}", error)
            let subber = SubberRef::new(accumulator.clone())
                .endowment(total_balance / 4)
                .unwrap_or_else(|error| {
                    panic!("failed at instantiating the Subber contract: {:?}", error)
            Self {
                which: Which::Adder,

For testing, how does one create code hashes to instantiate the main contract that will delegate calls downstream?

2 Answers 2


I'm posting a link to the discussion on GitHub: https://github.com/paritytech/ink/issues/1125.

AFAIK there is currently only the the possibility to do this with the redspot tool mentioned in the issue. I haven't tried it out myself though. Would be great if you could post in the issue if you managed to get it done.


Have a look in this link , Phala-Network is working on test cross-contract Ink! contracts and they have implemented cross-contract test in ink/examples/delegator/adder/ example

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.