Skip to content

Instantly share code, notes, and snippets.

@BellaBe
Last active December 29, 2022 15:07
Show Gist options
  • Save BellaBe/4abd49706eb86e31d99441184fb86a09 to your computer and use it in GitHub Desktop.
Save BellaBe/4abd49706eb86e31d99441184fb86a09 to your computer and use it in GitHub Desktop.
Create Smart contract with already deployed contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
// usage: contract is already deployed and instantiated, a reference to it is made by using its address
contract DeployedDemo{
uint private simpleUint;
constructor() payable{}
function getValue() public view returns(uint){
return simpleUint;
}
function setValue(uint _value) public{
simpleUint = _value;
}
}
contract ClientForAlreadyDeployedContract {
address contractAddress;
function setAddress(address _contractAddress)public{
contractAddress = _contractAddress;
}
function usePreviouslyDeployedContract() public returns(uint){
DeployedDemo deployedDemo = DeployedDemo(contractAddress);
deployedDemo.setValue(10);
return deployedDemo.getValue();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment