Selecting account 1 by default

When I start VS Code emulator, it select “Service accounts” as a default account, and I am manually selecting to account 1 to be able to deploy the smart contract. Unlike flow playground, it looks like I cannot keep deploying the same contract into same account as I get failed to save object: path /storage/NFTCollection in account 0x1cf0e2f2f715450 already stores an object . Therefore, I have to do this following logic, every time I save code.

  1. Stop emulator
  2. Start emulator
  3. Change account from service account to 1
  4. Click “Deploy”.

Are there any way to decrease the step? It’s a bit annoying that I have to go to the flow all the time.

I believe it’s more about the code of the contract, cause I’ve seen the same error during transaction.
You can solve this, by checking if there is resource in that path, like so:

if let oldToken <- acct.load<@ResourceType>(from: /storage/path) {
  destroy oldToken
}<@ResourceType>(<-newToken, to: /storage/path)

Though in a real-life you would probably need to be really careful about destroying resources like that. Cause there might be another dapp storing some resource on said path…

Hey Max, thanks for raising this, we’re working on a fix. Users should not have any reason to select the service account, so we’ll remove it from the list of selectable accounts. Will post soon when it’s fixed.

1 Like