Smart Contract

Donations_Alexandria

A.fed1adffd14ea9d0.Donations_Alexandria

Valid From

140,410,265

Deployed

1w ago
Feb 16, 2026, 06:54:42 PM UTC

Dependents

2 imports
1import FungibleToken from 0xf233dcee88fe0abe 
2import FlowToken from 0x1654653399040a61
3
4access(all) contract Donations_Alexandria {
5
6    // Total donated per address
7    access(self) var donations: {Address: UFix64}
8
9    // Public function to donate FlowToken to this contract
10    //
11    // - `from` is the vault sent in from the transaction
12    // - `donor` should be the address of the signer in the transaction
13    access(all) fun donate(from: @FlowToken.Vault, donor: Address) {
14        let amount: UFix64 = from.balance
15
16        let receiverRef = Donations_Alexandria.account.capabilities
17            .borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)
18            ?? panic("FlowToken receiver capability is not set up on contract account")
19
20        // Deposit tokens into the contract account's Flow vault
21        receiverRef.deposit(from: <- from)
22
23        // Update total donated per address
24        let current = self.donations[donor] ?? 0.0
25        self.donations[donor] = current + amount
26    }
27
28    // Returns a copy of the donations map
29    access(all) fun getDonations(): {Address: UFix64} {
30        return self.donations
31    }
32
33    // Convenience: get a specific address's total donated
34    access(all) fun getDonationTotal(address: Address): UFix64 {
35        return self.donations[address] ?? 0.0
36    }
37
38    init() {
39        self.donations = {}
40
41    }
42}