Cadence Cookbook

Contribute

Add Admin Resource to Account

Add Admin Resource to Account

01 Apr 2022

Contributed by Flow Blockchain

Intermediate

When you want to give someone else access to the admin resource.

Smart Contract Example
1 2 3 4 5 6 7 8 9 10 11 12 13 // Admin is a special authorization resource that // allows the owner to perform important NFT // functions // pub resource Admin { ..... pub fun createNewAdmin(): @Admin { return <-create Admin() } }

This code is used to create a new Admin resource which can then be saved to another users account

Transaction Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import SetAndSeries from 0x01 transaction { let adminCheck: &SetAndSeries.Admin prepare(acct: AuthAccount, acct2: AuthAccount) { self.adminCheck = acct.borrow<&SetAndSeries.Admin>(from: SetAndSeries.AdminStoragePath) ?? panic("could not borrow admin reference") acct2.save(<- self.adminCheck.createNewAdmin(), to: SetAndSeries.AdminStoragePath) } execute { log("New Admin Resource Created") } }

Before executing this transaction you first need to borrow the Admin resource from the 'acct'. Once that is borrowed, you then take 'acct2' and save the resource that is returned when you call the createNewAdmin() funtion to your storage path.


ProgressGetting Started With Access Management

100%


Related Recipes

01 Apr 2022
Admin Resource
Intermediate