github.com/onflow/flow-go@v0.33.17/fvm/blueprints/scripts/setupStorageForAccount.cdc (about)

     1  import FlowServiceAccount from 0xFLOWSERVICEADDRESS
     2  import FlowStorageFees from 0xFLOWSTORAGEFEESADDRESS
     3  import FungibleToken from 0xFUNGIBLETOKENADDRESS
     4  import FlowToken from 0xFLOWTOKENADDRESS
     5  
     6  // This transaction sets up storage on a auth account.
     7  // This is used during bootstrapping a local environment
     8  transaction() {
     9      prepare(account: AuthAccount, service: AuthAccount) {
    10  
    11          // take all the funds from the service account
    12          let tokenVault = service.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)
    13              ?? panic("Unable to borrow reference to the default token vault")
    14  
    15          let storageReservation <- tokenVault.withdraw(amount: FlowStorageFees.minimumStorageReservation) as! @FlowToken.Vault
    16          let hasReceiver = account.getCapability(/public/flowTokenReceiver)!.check<&{FungibleToken.Receiver}>()
    17          if !hasReceiver {
    18              FlowServiceAccount.initDefaultToken(account)
    19          }
    20          let receiver = account.getCapability(/public/flowTokenReceiver)!.borrow<&{FungibleToken.Receiver}>()
    21              ?? panic("Could not borrow receiver reference to the recipient's Vault")
    22  
    23          receiver.deposit(from: <-storageReservation)
    24      }
    25  }