That's how you can call a function and provide value to it.
The concept of value refers to Ethers sent along the call. The value is taken from the contract balance. You can't provide the value as a regular parameter inside ()
in Solidity if you want to send Ether, and not just some uint
which happens to be called value
.
Here's an example. If you call demo
(remember to include value when calling the function, otherwise the contract doesn't have any value to forward), the some
function call doesn't forward any value. But other
call forwards 6 weis. Note also that functions need to be declared payable
in order to be able to receive value.
contract A {
function demo() public payable {
B inst = new B();
inst.some(5);
inst.other{value: 6}();
}
}
contract B {
uint private _value;
function some(uint value) public {
_value = value;
}
function other() payable public {
}
}
You can see the syntax for example here: https://docs.soliditylang.org/en/latest/control-structures.html#external-function-calls