Basic Smart Contract Upgradeability Discussion

Indeed sir, those variables are not mean to be changed after you deploy a token, any case the token should have any method for it (although is not good practice to change those whenever you want, could run into issues with other contracts).

Any case, i think it can be done through the proxy contract.

Carlos Z

What exactly is the problem you’re having?
Is there a particular error message?

You must have new functions on the functional contract that are not in the storage contract.
The best way to get around this is through generic mappings which is detailed later in the course :slight_smile:

The constructor is just used in the first version of the functional contract, referencing back to storage, such that.

e.g.

string public immutable _stringStorage["_name"];

constructor (string name) {
  _stringStorage["_name"] = name;
}

and the function:

function name() public view returns (string memory) {
  return _strongStorage["_name"];
}

And future deployments can deploy contracts as:

import "./Version1.sol"

contract Version2 is Version1 {
  // Contract Code
}

So basically yeah all goo! Figured it out :slight_smile:

1 Like

For the getTheNumber function, when we use delegate call with it aren’t we making a simple view function into a function that costs gas ?

function getTheNumber() public  returns(bytes memory){
   (bool success, bytes memory data) = updContract.delegatecall(
        abi.encodeWithSignature("getNumber(uint256)")
    );
    return (data);
}

Instead this could have been

function getTheNumber() public view returns(uint256){
   return number
}

Since this is a simple view function, why are we using delegate call at all ?

Function doesn’t work with uint.

I am refering to the upgradeable contract code used in the simple first example of the course.

The first function below is the setter function in the proxy contract of Filip’s. He uses uint256. The second function is my function which is identical except that I use uint. My function doesn’t work, which confuses me because I am under the impression that uint is synonymous for uint256. So why doesn’t my function work? I have a feeling it has something to do with the function string that gets hashed. Any help would be very welcome.

function setNumberOfDogs(uint256 _number) public returns (bool, bytes memory){
        (bool res, bytes memory data) = currentAddress.delegatecall(abi.encodePacked(bytes4(keccak256("setNumberOfDogs(uint256)")), _number));
        return (res, data);
    }

    function setTheNumber(uint _number) public returns(bool, bytes memory) {
        (bool res, bytes memory data) = currentAddress.delegatecall(abi.encodePacked(bytes4(keccak256("setTheNumber(uint)")), _number));
        return (res, data);
    }   
    

in the quiz it says that the variables are stored in the Proxy… shouldn’t answer be storage contract?

Hi All,

I’ve a problem with truffle develop.

Everytime I enter that command it keeps loading.

This is my Truffle version

Truffle v5.0.14 (core: 5.0.14)
Solidity - 0.5.17 (solc-js)
Node v16.13.1
Web3.js v1.0.0-beta.37

Can someone tell me why it doesn’t work?

Hey @Sil, hope you are well.

Try following this guide to downgrade node to a older version, probably will do the trick (i use node v 12.0.0, its working fine for me) FAQ - How to downgrade Node.Js

Carlos Z

1 Like

Thank you very very much!!

I had to reset everything, but it did work (with “truffle init”).
Then I restarted my MacBook and it worked!
I then copied all code from my smart contract in the folder, and after everything was compiled, “truffle develop” worked.

If anyone get’s the same problem, you know what to do.

Hi @thecil
Can we call the functions of the functional contract by creating a interface of the functional contract instead of using the delegatecall ??

2 Likes

Hi All,

I tried to deploy de ProxyDog() contract but it appears this error.
creation of ProxyDog errored: Error encoding arguments: Error: invalid address (argument=“address”, value="", code=INVALID_ARGUMENT, version=address/5.5.0) (argument=null, value="", code=INVALID_ARGUMENT, version=abi/5.5.0)

pragma solidity 0.5.1;
import "./Storage.sol";

contract ProxyDog is Storage {
    address public currentAddress; 

    constructor(address _currentAddress) public {
        currentAddress = _currentAddress;
    }

    function upgrade(address _currentAddress) public {
        currentAddress = _currentAddress;
    }

    function getNumberOfDogs() public returns (bool, bytes memory) {
       (bool res, bytes memory data) = currentAddress.delegatecall(abi.encodePacked(bytes4(keccak256("getNumberOfDogs()"))));
        return (res, data);
    }

    function setNumberOfDogs(uint256 _number) public returns (bool, bytes memory){
        (bool res, bytes memory data) = currentAddress.delegatecall(abi.encodePacked(bytes4(keccak256("setNumberOfDogs(uint256)")), _number));
        return (res, data);
    }

}

Can someone tell me why is that ?

1 Like

yeah so the address value your passing into your constructor here is wrong and is not the correct type. can you past in a reply the exact format of the constructor values your using. they should be wrapped in quotes usually so "0x1234..." like that

1 Like

Thanks very much. Also I realized that I haven’t put the address before deploy. That’s why the error. :smile:

1 Like