Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs fixes #115

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 9 additions & 3 deletions documentation/use_in_zk_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@ 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 {
SmartContract, state, State, method, DeployArgs, PublicKey, UInt64
} from 'o1js';
kantp marked this conversation as resolved.
Show resolved Hide resolved

import { FungibleToken } from 'mina-fungible-token';
kantp marked this conversation as resolved.
Show resolved Hide resolved

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
Loading