Do you know if is it possible to call the function of an other contract in Solidity used in Substrate based chain and compiled with solang ? At first glance it seems impossible but I doubt it.
As a basic example I'm trying to get a "incrementor" working only if a "flipper" is on:
contract Flipper {
bool private value;
constructor (bool initValue) {
value = initValue;
}
function flip () public {
value = !value;
}
function get () public view returns (bool) {
return value;
}
}
I want to use a Flipper instance in my Incrementor contract to allow / disallow incrementing.
import "flipper.sol";
contract Incrementor {
uint256 _count;
Flipper _flipper;
constructor (uint256 _initialValue, Flipper _flipperContract) {
_count = _initialValue;
_flipper = _flipperContract;
}
// --
// Mutators
// --
function increment () public {
require(_flipper.get(), "Flipper must be ON");
_count += 1;
}
function superFlip () public {
_flipper.flip();
}
function setValue (uint256 v) public {
_count = v;
}
// --
// Accessors
// --
function count () public view returns (uint256) {
return _count;
}
}
When testing all of this on polkadotjs; I have a negative answer saying contract trapped ALONG with a success message (but the totality doesn't work).
(Failure on the "increment" message):
I'm not sure but I suspect this problem to arise from the difference in addressing in the EVM vs WASM.
In the article linked bellow, we can see how an external contract function is "manually" invoked with an "address.call(bytes4(keccack25('...')), args)".
https://medium.com/@blockchain101/calling-the-function-of-another-contract-in-solidity-f9edfa921f4c
Except this is working in a EVM environment; not a WASM substrate environment.
Solang Version : v0.1.9 https://github.com/hyperledger-labs/solang/releases/tag/v0.1.9
Substrate Version: v4.0.0-dev
Contract Node version: 0.6.0 https://github.com/paritytech/substrate-contracts-node
Contracts deployed from PolkadotJS api v7.8.1 apps v0.105.2-27
Can someone help ?
substrate-contracts-node --version
. Also, couldn't it just be that yourrequire
evaluates to false? In that case it would also trap.