4

I know that there is no contract instance copy implementation (yet) in solidity but what would be the best way to backup a contract?

Suppose the following scenario:

  • contract is deployed to the block chain
  • contract has a number of attributes that each have a getter() method callable by the owner (an address)
  • contract is populated with new data
  • the contract needs a new functionality (implemented through a new set of methods)
  • a new contract is developed and deployed to the network but it needs the data from the previous contract

How can the new contract retrieve the state of the previous contract?

The trivial approach would be to use getters for all attributes in the original contract and setters in the new contract and simply copy the attributes from one contract to another.

Sebi
  • 5,294
  • 6
  • 27
  • 52

1 Answers1

2

what would be the best way to backup a contract?

There's no need to backup a contract. Contracts run on the global peer-to-peer network and are accessible as long as there is a single node on the network.

the contract needs a new functionality (implemented through a new set of methods)

See Upgradeable smart contracts if that is the actual problem.

The trivial approach would be to use getters for all attributes in the original contract and setters in the new contract and simply copy the attributes from one contract to another.

That works and is a valid approach depending on the use case. Similarly, it can also be a valid approach for one contract to simply call another contract's getter and use that value, without copying and storing it itself.

eth
  • 85,679
  • 53
  • 285
  • 406
  • 1
    I mean that I want to "clone" the contract with all its attribute values into a new one (assign the new contract those values) and then remove the old contract (I don't want derelict contracts with outdated data to pollute the block chain). – Sebi Aug 18 '16 at 08:40