Skip to content

Commit 5d698c0

Browse files
committed
Debug tx
1 parent da8fc14 commit 5d698c0

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

cadence/transactions/withdraw_token.cdc

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,52 @@ import "ExampleToken"
55
// that owns a Vault
66
transaction {
77

8-
// Temporary Vault object that holds the balance being transferred
98
var temporaryVault: @ExampleToken.Vault
9+
var receiver: Capability<&{ExampleToken.Receiver}>
10+
var receiverRef: &{ExampleToken.Receiver}
11+
let mintingRef: &ExampleToken.VaultMinter
1012

1113
prepare(acct: auth(Storage, Capabilities) &Account) {
12-
// Step 1: Check if a Vault exists, else create one
14+
// Check if a Vault exists, else create one
1315
if acct.storage.borrow<&ExampleToken.Vault>(from: /storage/MainVault) == nil {
1416
let newVault <- ExampleToken.createEmptyVault()
1517
acct.storage.save<@ExampleToken.Vault>(<-newVault, to: /storage/MainVault)
1618
log("New Vault created and saved to storage")
1719
}
1820

19-
// Step 2: Mint 50 tokens into the Vault using VaultMinter
20-
let minterRef = acct.storage.borrow<&ExampleToken.VaultMinter>(
21+
// Mint 50 tokens into the Vault using VaultMinter
22+
let minter = acct.storage.borrow<&ExampleToken.VaultMinter>(
2123
from: /storage/CadenceFungibleTokenTutorialMinter
22-
) ?? panic("Could not borrow a reference to the VaultMinter")
23-
24-
let recipientCap = acct.capabilities.storage.issue<auth(ExampleToken.Receiver) &ExampleToken.Vault>(
24+
) ?? panic("Could not borrow a reference to the minter")
25+
self.mintingRef = minter
26+
27+
// Issue a Receiver capability for the caller's Vault
28+
let receiverCap = acct.capabilities.storage.issue<&{ExampleToken.Receiver}>(
2529
/storage/MainVault
2630
)
27-
minterRef.mintTokens(amount: 50.0, recipient: recipientCap)
31+
self.receiver = receiverCap
32+
33+
self.mintingRef.mintTokens(amount: 30.0, recipient: self.receiver)
2834
log("Minted 50 tokens into the Vault")
2935

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

35-
// Step 4: Withdraw 10 tokens into the temporary Vault
41+
// Withdraw 10 tokens into the temporary Vault
3642
self.temporaryVault <- vaultRef.withdraw(amount: 10.0)
37-
log("Withdrawn 10 tokens into temporary Vault")
38-
}
39-
4043

41-
execute {
42-
// Get the recipient's public account object
43-
let recipient = getAccount(0x01)
44+
log("Withdrawn 10 tokens into temporary Vault")
4445

45-
// Borrow the recipient's Receiver capability for their Vault
46-
let receiverRef = recipient.capabilities.get<&ExampleToken.Vault>(
47-
/public/MainReceiver
48-
).borrow() ?? panic("Could not borrow a Receiver reference from the recipient's Vault")
46+
self.receiverRef = acct.storage.borrow<&{ExampleToken.Receiver}>(
47+
from: /storage/MainVault
48+
) ?? panic("Could not borrow a Receiver reference to the account's Vault")
4949

50-
// Deposit the tokens into the recipient's Vault
51-
receiverRef.deposit(from: <-self.temporaryVault)
50+
}
5251

53-
log("Transfer succeeded!")
52+
execute {
53+
self.receiverRef.deposit(from: <-self.temporaryVault)
54+
log("Tokens successfully deposited!")
5455
}
5556
}

0 commit comments

Comments
 (0)