github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/docs/reference/stdlibs/std/coins.md (about)

     1  ---
     2  id: coins
     3  ---
     4  
     5  # Coins
     6  
     7  `Coins` is a set of `Coin`, one per denomination.
     8  
     9  ```go
    10  type Coins []Coin
    11  func (c Coins) String() string {...}
    12  func (c Coins) AmountOf(denom string) int64 {...}
    13  func (c Coins)  Add(other Coins) Coins {...}
    14  ```
    15  
    16  ### String
    17  Returns a string representation of the `Coins` set it was called upon.
    18  
    19  #### Usage
    20  ```go
    21  coins := std.Coins{std.Coin{"ugnot", 100}, std.Coin{"foo", 150}, std.Coin{"bar", 200}}
    22  coins.String() // 100ugnot,150foo,200bar
    23  ```
    24  ---
    25  
    26  ### AmountOf
    27  Returns **int64** amount of specified coin within the `Coins` set it was called upon. Returns `0` if coin specified coin does not exist in the set. 
    28  
    29  ### Parameters
    30  - `denom` **string** denomination of specified coin
    31  
    32  #### Usage
    33  ```go
    34  coins := std.Coins{std.Coin{"ugnot", 100}, std.Coin{"foo", 150}, std.Coin{"bar", 200}}
    35  coins.AmountOf("foo") // 150
    36  ```
    37  ---
    38  
    39  ### Add
    40  Adds (or updates) the amount of specified coins in the `Coins` set. If the specified coin does not exist, `Add` adds it to the set. 
    41  
    42  ### Parameters
    43  - `other` **Coins** to add to `Coins` set
    44  
    45  #### Usage
    46  ```go
    47  coins := // ...
    48  otherCoins := // ...
    49  coins.Add(otherCoins)
    50  ```