-
Notifications
You must be signed in to change notification settings - Fork 52
/
setup_account.cdc
39 lines (30 loc) · 1.59 KB
/
setup_account.cdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// This transaction is a template for a transaction to allow
// anyone to add a Vault resource to their account so that
// they can use the exampleToken
import "FungibleToken"
import "ExampleToken"
import "ViewResolver"
import "FungibleTokenMetadataViews"
transaction () {
prepare(signer: auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue) &Account) {
let vaultData = ExampleToken.resolveContractView(resourceType: nil, viewType: Type<FungibleTokenMetadataViews.FTVaultData>()) as! FungibleTokenMetadataViews.FTVaultData?
?? panic("ViewResolver does not resolve FTVaultData view")
// Return early if the account already stores a ExampleToken Vault
if signer.storage.borrow<&ExampleToken.Vault>(from: vaultData.storagePath) != nil {
return
}
let vault <- ExampleToken.createEmptyVault(vaultType: Type<@ExampleToken.Vault>())
// Create a new ExampleToken Vault and put it in storage
signer.storage.save(<-vault, to: vaultData.storagePath)
// Create a public capability to the Vault that exposes the Vault interfaces
let vaultCap = signer.capabilities.storage.issue<&ExampleToken.Vault>(
vaultData.storagePath
)
signer.capabilities.publish(vaultCap, at: vaultData.metadataPath)
// Create a public Capability to the Vault's Receiver functionality
let receiverCap = signer.capabilities.storage.issue<&ExampleToken.Vault>(
vaultData.storagePath
)
signer.capabilities.publish(receiverCap, at: vaultData.receiverPath)
}
}