'solidity call and delegatecall caller address
I'm working on an ERC721 contract and am trying to implement an adminBurn function from another smart contract. The purpose is to let users burn the token via the specific smart contract (admin contract) deployed.
However, regardless of using call or delegatecall, the caller address is always the msg.sender address instead of the adminContract address.
Would you mind informing me what the problem is?
The ERC721 contract is as follows:
pragma solidity 0.8.11;
...
contract test is ERC721 {
...
modifier onlyAdmin() {
require(tx.origin == adminContract, "transaction is not sent from an admin
contract for ERC721");
_;
}
function adminBurn(
uint256 tokenId
) external onlyAdmin {
_burn(tokenId);
}
function setAdminContractAddress(address _adminContract) external onlyOwner{
adminContract = _adminContract;
emit adminContractSet(adminContract);
}
}
And the admin contract is as follows:
pragma solidity 0.8.11;
...
contract adminContract is Ownable{
...
function _callAdminBurn(address _ERC721, uint256 id) internal {
bytes memory payload = abi.encodeWithSignature("adminBurn(uint256)",id);
(bool success, bytes memory result) = _ERC721.call(payload);
emit adminBurnByCall(_acceptedERC1155, success, result);
}
function _delegatecallAdminBurn(address _ERC721, uint256 id) internal {
bytes memory payload = abi.encodeWithSignature("adminBurn(uint256)",id);
(bool success, bytes memory result) = _ERC721.delegatecall(payload);
emit adminBurnByCall(_acceptedERC1155, success, result);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
