10

I find answer how to make upgradable contract here

How to call function from currentVersion with fallback function on web3?

    contract Relay {
    address public currentVersion;
    address public owner;

    function Relay(address initAddr){
        currentVersion = initAddr;
        owner = msg.sender;
    }

    function update(address newAddress){
        if(msg.sender != owner) throw;
        currentVersion = newAddress;
    }

    function(){
        if(!currentVersion.delegatecall(msg.data)) throw;
    }
}
eth
  • 85,679
  • 53
  • 285
  • 406
Agniezhk
  • 321
  • 1
  • 3
  • 7
  • Related: https://ethereum.stackexchange.com/questions/20972/how-to-make-function-call-through-relay-entry-level-contract – eth Aug 02 '17 at 03:36
  • I am also trying to get the answer of this question. – Aniket Aug 11 '17 at 11:08

2 Answers2

6

You can do this with the sendTransaction function, like so:

web3.eth.sendTransaction({
  from: sendingAccount,
  to: contract.address,
  data: yourData, // optional, if you want to pass data or specify another function to be called by delegateCall you do that here
  gas: requiredGas, // technically optional, but you almost certainly need more than the default 21k gas
  value: value //optional, if you want to pay the contract Ether
});
Steve Ellis
  • 1,357
  • 13
  • 21
  • will contract.address be the address of Relay or the actual contract? – Rahul Kothari Aug 06 '18 at 10:00
  • And what/how do I write instead of yourData (I want to call a method set() from a contract Contract1. This doesn't seem to work:
     var encodedABI = addDetails.encodeABI(); ```
    And instead of  `yourData` I wrote `encodedABI`. Using web3 0.20.
    
    – Rahul Kothari Aug 06 '18 at 10:13
0

You probably don't need it anymore, but you can retype the Relay address to instance contract:

contract Instance{
   function doSomething(){ ... }
}

and then if Relay.deployed() is at address 0x12345678, do:

in = Instance.at('0x12345678')
in.then(function(i){ i.doSomething(); })
ejossev
  • 13
  • 2