Skip to content

Commit

Permalink
Debug tx
Browse files Browse the repository at this point in the history
  • Loading branch information
lealobanov committed Dec 17, 2024
1 parent fa211d2 commit da8fc14
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions cadence/transactions/withdraw_token.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,35 @@ transaction {
var temporaryVault: @ExampleToken.Vault

prepare(acct: auth(Storage, Capabilities) &Account) {

// Step 1: Check if a Vault already exists, if not, create and save one
// Step 1: Check if a Vault exists, else create one
if acct.storage.borrow<&ExampleToken.Vault>(from: /storage/MainVault) == nil {
let newVault <- ExampleToken.createEmptyVault()
acct.storage.save<@ExampleToken.Vault>(<-newVault, to: /storage/MainVault)

log("New Vault created and saved to storage")
}

// Step 2: Borrow the Vault reference with the Withdraw entitlement
// Step 2: Mint 50 tokens into the Vault using VaultMinter
let minterRef = acct.storage.borrow<&ExampleToken.VaultMinter>(
from: /storage/CadenceFungibleTokenTutorialMinter
) ?? panic("Could not borrow a reference to the VaultMinter")

let recipientCap = acct.capabilities.storage.issue<auth(ExampleToken.Receiver) &ExampleToken.Vault>(
/storage/MainVault
)
minterRef.mintTokens(amount: 50.0, recipient: recipientCap)
log("Minted 50 tokens into the Vault")

// Step 3: Borrow the Vault with Withdraw entitlement
let vaultRef = acct.storage.borrow<auth(ExampleToken.Withdraw) &ExampleToken.Vault>(
from: /storage/MainVault
) ?? panic("Could not borrow a reference to the sender's Vault with Withdraw entitlement")
) ?? panic("Could not borrow a reference to the sender's Vault")

// Step 3: Withdraw 10 tokens into the temporary Vault
// Step 4: Withdraw 10 tokens into the temporary Vault
self.temporaryVault <- vaultRef.withdraw(amount: 10.0)

log("Withdrawn 10 tokens into temporary Vault")
}


execute {
// Get the recipient's public account object
let recipient = getAccount(0x01)
Expand Down

0 comments on commit da8fc14

Please sign in to comment.