Migration Guide

1 min read

v0.11

Version 0.11 introduced breaking changes: Paths are now typed, i.e. there are specific subtypes for storage, public, and private paths, and the Storage API has been made type-safer by changing parameter types to more specific path types.

Please read the release notes linked above to learn more.

The following hints should help with updating your Cadence code:

  • The return types of PublicAccount.getCapability and AuthAccount.getCapability are not optional anymore.

    For example, in the following code the force unwrapping should be removed:

    1
    let balanceRef = account
    2
    - .getCapability(/public/flowTokenBalance)!
    3
    + .getCapability(/public/flowTokenBalance)
    4
    .borrow<&FlowToken.Vault{FungibleToken.Balance}>()!

    In the next example, optional binding was used and is not allowed anymore:

    1
    - if let balanceCap = account.getCapability(/public/flowTokenBalance) {
    2
    - return balanceCap.borrow<&FlowToken.Vault{FungibleToken.Balance}>()!
    3
    - }
    4
    5
    + let balanceCap = account.getCapability(/public/flowTokenBalance)
    6
    + return balanceCap.borrow<&FlowToken.Vault{FungibleToken.Balance}>()!
  • Parameters of the Storage API functions that had the type Path now have more specific types. For example, the getCapability functions now require a CapabilityPath instead of just a Path.

    Ensure path values with the correct path type are passed to these functions.

    For example, a contract may have declared a field with the type Path, then used it in a function to call getCapability. The type of the field must be changed to the more specific type:

    1
    pub contract SomeContract {
    2
    3
    - pub let somethingPath: Path
    4
    + pub let somethingPath: StoragePath
    5
    6
    init() {
    7
    self.somethingPath = /storage/something
    8
    }
    9
    10
    pub fun borrow(): &Something {
    11
    return self.account.borrow<&Something>(self.somethingPath)
    12
    }
    13
    }