Skip to content

Instantly share code, notes, and snippets.

@nakajo2011
Last active January 9, 2025 07:23
Show Gist options
  • Save nakajo2011/6f4a0fe380e84ecc353d8deeb4782077 to your computer and use it in GitHub Desktop.
Save nakajo2011/6f4a0fe380e84ecc353d8deeb4782077 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.26+commit.8a97fa7a.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
contract Storage {
uint256 number;
function store(uint256 num) public {
number = num;
}
function retrieve() public view returns (uint256){
return number;
}
}
contract Caller {
Storage storageContract;
uint256 copied;
constructor(address storage_addr) {
storageContract = Storage(storage_addr);
}
function copyFrom() public {
copied = storageContract.retrieve();
}
function getCopyNum() public view returns(uint) {
return copied;
}
function getNumAt(address storage_addr) public view returns(uint) {
Storage s = Storage(storage_addr);
return s.retrieve();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment