Skip to content

Commit

Permalink
Docs fixes (#115)
Browse files Browse the repository at this point in the history
Co-authored-by: Philipp Kant <[email protected]>
  • Loading branch information
egeaybars123 and kantp authored Jan 3, 2025
1 parent e5833c8 commit 8dbf75a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion documentation/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ can be found on [github](https://github.com/MinaFoundation/mina-fungible-token),
[npm package](https://www.npmjs.com/package/mina-fungible-token).

The fungible token standard uses Mina's native support for custom tokens (see
[MIP-4](https://github.com/MinaProtocol/MIPs/blob/main/MIPS/mip-zkapps.md#token-mechanics)). An
[MIP-4](https://github.com/MinaProtocol/MIPs/blob/main/MIPS/mip-0004-zkapps.md#token-mechanics)). An
account on Mina can be created to hold either Mina, or a custom token.

To create a new token, one creates a smart contract, which becomes the owner for the token, and uses
Expand Down
10 changes: 7 additions & 3 deletions documentation/use_in_zk_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,32 @@ Interacting with tokens from a zkApp is as simple as writing off-chain code (sam
previous chapter is executed from within zkApp methods):

```ts
import { DeployArgs, method, PublicKey, SmartContract, State, state, UInt64 } from "o1js"

import { FungibleToken } from "mina-fungible-token"

export class TokenEscrow extends SmartContract {
@state(PublicKey)
tokenAddress = State<PublicKey>()
@state(UInt64)
total = State<UInt64>()

deploy(args: DeployArgs & { tokenAddress: PublicKey }) {
async deploy(args: DeployArgs & { tokenAddress: PublicKey }) {
super.deploy(args)
this.tokenAddress.set(args.tokenAddress)
this.total.set(UInt64.zero)
}

@method
deposit(from: PublicKey, amount: UInt64) {
async deposit(from: PublicKey, amount: UInt64) {
const token = new FungibleToken(this.tokenAddress.getAndRequireEquals())
token.transfer(from, this.address, amount)
const total = this.total.getAndRequireEquals()
this.total.set(total.add(amount))
}

@method
withdraw(to: PublicKey, amount: UInt64) {
async withdraw(to: PublicKey, amount: UInt64) {
const token = new FungibleToken(this.tokenAddress.getAndRequireEquals())
const total = this.total.getAndRequireEquals()
total.greaterThanOrEqual(amount)
Expand Down

0 comments on commit 8dbf75a

Please sign in to comment.