This question is an extension of this previous question where this commit of this Pull Request I used a modified version of this ink! basic-contract-caller example where there is a BasicContractCaller
main contract and a OtherContract
sub-contract.
But this question relates to changes I made to that code by using the Builders approach section's CreateBuilder
and CallBuilder
as mentioned in the ink! documentation here.
The Builder approach that I implemented is in this commit.
To run it, I follow the steps in the README file and then after entering the Docker container I run cd /app && ./docker/quickstart-basic-contract-caller.sh
and it runs through these steps:
- Starts a fresh local node using substrate-contracts-node
- Builds both of those contracts
- Uploads both of those contracts
- Instantiates both of those contracts with
cargo contract instantiate --manifest-path $PARENT_DIR/dapps/basic_contract_caller/Cargo.toml --suri //Alice --constructor new --args $CODE_HASH_SUB $CONTRACT_ADDR_SUB --execute --gas 200000000000 --proof-size 100000000000 --skip-confirm
. Note: It was necessary to provide more gas--gas 200000000000
otherwise I got errorThe executed contract exhausted its gas limit
. Note: It was also necessary to use.endowment(0)
, otherwise I got errorCross-contract instantiation failed with TransferFailed
. - Calls a setter method
flip()
in the sub-contract directlycargo contract call --suri //Alice --contract $CONTRACT_ADDR_SUB --message get --execute --gas 200000000000 --proof-size 100000000000 --skip-confirm
- Calls a getter method
get()
in the sub-contract directly withcargo contract call --suri //Alice --contract $CONTRACT_ADDR_SUB --message get --execute --skip-confirm
- Calls a method
get()
in the main contract that calls a getter methodget()
in the sub-contractcargo contract call --suri //Alice --contract $CONTRACT_ADDR_MAIN --message get --execute --skip-confirm
.
Based on that ink! documentation I thought it was necessary to remove use of Contract Ref from the Contract References Approach if I was going to use the Builder approach instead, however I was not able remove having to import the sub-contract that I want to call as a dependency of the main contract since in the documentation here it seems necessary to provide the Contract Ref in the Builder Approach implementation example like this build_create::<OtherContractRef>()
.
Whilst I was able to get the above steps 0-5 to work, I wasn't able to solve the previous question, and I got errors running step 6, which calls the sub-contract via the main contract, since it outputs:
Calling contract method get ...
ERROR: Pre-submission dry-run failed. Use --skip-dry-run to skip this step.
And I then ran it with --skip-dry-run
as the error suggests I do by adding these additional options here:
--gas 200000000000
--proof-size 100000000000
--skip-dry-run
then instead it outputs the below error, which based on this question, which indicates that a panic has occurred, but in that get()
method in the main contract here I feel like I'm already handling errors appropriately, and the get()
method it should call in the sub-contract is basic as shown here.
Calling contract method get ...
ERROR: ModuleError: Contracts::ContractTrapped: ["Contract trapped during execution."]
How would I fully remove using Contracts Ref now that I'm using the Builders Approach incase that is the cause of the error??
Note: Unfortunately it doesn't seem possible to debug using this Builder Approach though. They highlight this limitation in the ink! documentation You will not be able to get any feedback about this at at compile time. You will only find out your call failed at runtime!.