diff --git a/cadence/transactions/withdraw_token.cdc b/cadence/transactions/withdraw_token.cdc index 9754ec5..ef64af8 100644 --- a/cadence/transactions/withdraw_token.cdc +++ b/cadence/transactions/withdraw_token.cdc @@ -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( + /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( 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)