-
Notifications
You must be signed in to change notification settings - Fork 53
/
setup_account.cdc
25 lines (19 loc) · 1.05 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
import NFTStorefrontV2 from "../contracts/NFTStorefrontV2.cdc"
/// This transaction installs the Storefront ressource in an account.
///
transaction {
prepare(acct: auth(IssueStorageCapabilityController, PublishCapability, Storage) &Account) {
// If the account doesn't already have a Storefront
if acct.storage.borrow<&NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath) == nil {
// Create a new empty Storefront
let storefront <- NFTStorefrontV2.createStorefront() as! @NFTStorefrontV2.Storefront
// save it to the account
acct.storage.save(<-storefront, to: NFTStorefrontV2.StorefrontStoragePath)
// create a public capability for the Storefront
let storefrontPublicCap = acct.capabilities.storage.issue<&{NFTStorefrontV2.StorefrontPublic}>(
NFTStorefrontV2.StorefrontStoragePath
)
acct.capabilities.publish(storefrontPublicCap, at: NFTStorefrontV2.StorefrontPublicPath)
}
}
}