osmosis-labs/beaker

getState()?.counter.addresses.default missing "default" attribute when deploy the contract with --label

ApexTone opened this issue · 6 comments

To replicate: follow the instruction on https://docs.osmosis.zone/cosmwasm/testnet/cosmwasm-beaker from "Install Beaker" to "Deploy contract on permissionless network" and inspect the content of the following files: frontend/lib/state.ts (line 15) and frontend/.beaker/state.json

At frontend/lib/state.ts (line 15), there's a usage for getState()?.counter.addresses.default to get the smart contract address.
getState() will return the data taken from the file frontend/.beaker/state.json and frontend/.beaker/state.local.json. After further investigation, I've found out that state.json is missing the "default" property within "addresses" and the content is as follows:

  "testnet": {
    "counter": {
      "code_id": 1479,
      "addresses": {
        "My first Beaker Contract": "<address>"
      },
      "proposal": {
        "store_code": 56909
      }
    }
  }
}

This could be the problem from the code generation of Beaker.

I've tried running the following command with and without --label

beaker wasm deploy counter --signer-account test1 --network testnet --no-wasm-opt --raw '{ "count": 0 }' --label 'My first Beaker Contract'

and it seems that the --label is the cause of the problem.

My current workaround is to change the attribute name from "My first Beaker Contract" to "default".

@daniel-farina should we update the doc by removing label to not confuse people when they use it with pre-generated frontend?

@ApexTone changing getState()?.counter.addresses.default to getState()?.counter.addresses["My first Beaker Contract"] should also works.

Yes, it did work. At first, I was uncertain if the "default" attribute would be used in other places so I add the attribute to the state.json to avoid further complications.

@ApexTone state.json shouldn't be manually update or else it might cause more confusion down the line. The intended use of that is for when you instantiate contract from the same code with different initial setup or intended use, you can differentiate them.

Oh, I see. Thank you for the clarification!

Will close this issue then!