How could I create a new smart contract token and copy the balance of every address from an old contract.

Essentially fork a contract.

I want to make this a one time function in the contract so that it can only be called once. Or even better do it during the contract creation.

  • Is the smart contract to be forked already written or are you able to change it's code before it's deployment in anticipation of a possible fork? Commented Feb 21, 2018 at 22:24
  • It is already deployed. Been deployed for a year.
    – James
    Commented Feb 21, 2018 at 22:30
  • Is it a standard ERC20 token? Is the balance variable public? Commented Feb 21, 2018 at 22:40
  • Okay wait, I am going to write you and answer, but it is not as easy as you think. Commented Feb 21, 2018 at 23:01

1 Answer 1


You can create a new contract with method to get every addresses in the token contract, then you can just copy it to your own array of address and then just call balanceOf function and get the balance of all your new address accounts. It's simple if you are copy a erc20 token.

  • I know that, but I am not sure what code to write. I was hoping to get some code.
    – James
    Commented Feb 21, 2018 at 22:20
  • You can use the ""call" function after you create a instance of your token contract with its address Commented Feb 21, 2018 at 22:39
  • You can see it. It is public. Go to etherscan it is called OhniToken
    – James
    Commented Feb 21, 2018 at 22:42

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