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;
    }
}
2

2 Answers 2

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
});
2
  • will contract.address be the address of Relay or the actual contract? Aug 6, 2018 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 addDetails = await Contract1.set(1) var encodedABI = addDetails.encodeABI(); And instead of yourData I wrote encodedABI. Using web3 0.20. Aug 6, 2018 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(); })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.