osmosis-labs / beaker

Beaker helps streamlining CosmWasm development workflow.
Apache License 2.0
106 stars 30 forks source link

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

Closed ApexTone closed 1 year ago

ApexTone commented 1 year ago

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".

iboss-ptk commented 1 year ago

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

iboss-ptk commented 1 year ago

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

ApexTone commented 1 year ago

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.

iboss-ptk commented 1 year ago

@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.

ApexTone commented 1 year ago

Oh, I see. Thank you for the clarification!

iboss-ptk commented 1 year ago

Will close this issue then!