Encontré la respuesta sobre cómo hacer un contrato actualizable aquí .
¿Cómo llamar a la función desde la versión actual con la función de respaldo en 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;
}
}
Puede hacer esto con la función sendTransaction , así:
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
});
contract.address
la dirección de Relay o el contrato real?yourData
(Quiero llamar a un método set()
desde un contrato ) Contract1
. Esto no parece funcionar: var addDetails = await Contract1.set(1) var encodedABI = addDetails.encodeABI();
Y en lugar de yourData
Escribí encodedABI
. Usando web3 0.20.Probablemente ya no lo necesite, pero puede volver a escribir la dirección de retransmisión en el contrato de instancia:
contract Instance{
function doSomething(){ ... }
}
y luego, si Relay.deployed() está en la dirección 0x12345678, haz lo siguiente:
in = Instance.at('0x12345678')
in.then(function(i){ i.doSomething(); })
ética
Aniket