i'm working on solidity for Dapp dev.
Let me assume this situation below, with 2 contracts, A
and B
.
contract A {
B contract_b;
constructor(address b_addr) {
contract_b = B(b_addr);
}
function pass() public {
contract_b.do_sth();
}
}
contract B {
constructor(address b_addr) {
//
}
function do_sth() external {
// do something state-changing stuffs //
}
}
I vaguely noticed that view function does not spend gas,
so if do_sth()
is view
function, then nothings' bothering.
but with debugging, i found that in processing do_sth()
invoked by pass()
,
msg.sender
becomes the constact address of A, not the original sender.
which means, in do_sth()
scope, msg.sender
is changed.
Then, whose gas will be consumed for do_sth()
process?
Each Ethereum transaction has a gas attached to it and only this gas can be spent during the processing of the transaction. Any contract calls count against the original transaction and contracts cannot pay the gas fee themselves.