github.com/koko1123/flow-go-1@v0.29.6/fvm/blueprints/scripts/setupAccountTemplate.cdc (about)

     1  // This transaction is a template for a transaction
     2  // to add a Vault resource to their account
     3  // so that they can use the flowToken
     4  
     5  import FungibleToken from 0xFUNGIBLETOKENADDRESS
     6  import FlowToken from 0xFLOWTOKENADDRESS
     7  
     8  transaction {
     9  
    10      prepare(signer: AuthAccount) {
    11  
    12          if signer.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault) == nil {
    13              // Create a new flowToken Vault and put it in storage
    14              signer.save(<-FlowToken.createEmptyVault(), to: /storage/flowTokenVault)
    15  
    16              // Create a public capability to the Vault that only exposes
    17              // the deposit function through the Receiver interface
    18              signer.link<&FlowToken.Vault{FungibleToken.Receiver}>(
    19                  /public/flowTokenReceiver,
    20                  target: /storage/flowTokenVault
    21              )
    22  
    23              // Create a public capability to the Vault that only exposes
    24              // the balance field through the Balance interface
    25              signer.link<&FlowToken.Vault{FungibleToken.Balance}>(
    26                  /public/flowTokenBalance,
    27                  target: /storage/flowTokenVault
    28              )
    29          }
    30      }
    31  }