github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/blueprints/scripts/setupStorageForAccount.cdc (about) 1 import FlowServiceAccount from "FlowServiceAccount" 2 import FlowStorageFees from "FlowStorageFees" 3 import FungibleToken from "FungibleToken" 4 import FlowToken from "FlowToken" 5 6 // This transaction sets up storage on a auth account. 7 // This is used during bootstrapping a local environment 8 transaction() { 9 prepare( 10 account: auth(SaveValue, Capabilities) &Account, 11 service: auth(BorrowValue) &Account 12 ) { 13 // take all the funds from the service account 14 let tokenVault = service.storage 15 .borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault) 16 ?? panic("Unable to borrow reference to the default token vault") 17 18 let storageReservation <- tokenVault.withdraw(amount: FlowStorageFees.minimumStorageReservation) as! @FlowToken.Vault 19 20 let hasReceiver = account.capabilities 21 .get<&{FungibleToken.Receiver}>(/public/flowTokenReceiver).check() 22 if !hasReceiver { 23 FlowServiceAccount.initDefaultToken(account) 24 } 25 26 let receiver = account.capabilities 27 .borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver) 28 ?? panic("Could not borrow receiver reference to the recipient's Vault") 29 30 receiver.deposit(from: <-storageReservation) 31 } 32 }