7.1 Writing and Deploying
Repeat the same steps used in the previous example to create a new file in Remix.
Paste:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract WalletAuth {
address public owner;
constructor() {
owner = msg.sender;
}
function restrictedAction() public view returns (string memory) {
require(msg.sender == owner, "Not authorized");
return "Access granted";
}
}Here:
msg.sender represents the wallet calling the function
the constructor sets the deployer as the owner
access is restricted using require()
Previous7. Smart Contract Example : Wallet Authorization (Understanding msg. sender and Permissions
Next7.2 Executing the Contract
Last updated