Fallback-Funktion in web3

Ich finde hier eine Antwort, wie man einen aktualisierbaren Vertrag abschließt

Wie rufe ich die Funktion von der aktuellen Version mit der Fallback-Funktion auf web3 auf?

    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;
    }
}
Auch auf diese Frage versuche ich eine Antwort zu bekommen.

Antworten (2)

Sie können dies mit der sendTransaction- Funktion wie folgt tun:

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
});
wird contract.addressdie Adresse von Relay oder der eigentliche Vertrag sein?
Und was/wie schreibe ich statt yourData(Ich möchte eine Methode set()aus einem Vertrag aufrufen Contract1. Das scheint nicht zu funktionieren: var addDetails = await Contract1.set(1) var encodedABI = addDetails.encodeABI(); Und statt yourDataich schrieb encodedABI. Mit web3 0.20.

Sie brauchen es wahrscheinlich nicht mehr, aber Sie können die Relay-Adresse erneut in den Instanzvertrag eingeben:

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

und wenn sich Relay.deployed() an der Adresse 0x12345678 befindet, tun Sie Folgendes:

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