$npx -y skills add keep-starknet-strange/starknet-agentic --skill starknet-tongoConfidential ERC20 payments on Starknet using Tongo protocol. Fund, transfer, withdraw, and rollover encrypted token balances with zero-knowledge proofs. Use when the user needs privacy-preserving transactions, confidential payments, encrypted balances, or auditable private trans
| 1 | # Starknet Tongo Skill |
| 2 | |
| 3 | Confidential ERC20 payments on Starknet using the [Tongo protocol](https://github.com/fatlabsxyz/tongo). Tongo wraps any ERC20 token into encrypted balances using ElGamal encryption and zero-knowledge proofs. No trusted setup required. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | - Confidential ERC20 payment flows that require encrypted balances or private transfers. |
| 8 | - Compliance or auditor-enabled privacy flows built on top of Tongo accounts. |
| 9 | |
| 10 | ## When NOT to Use |
| 11 | |
| 12 | - Standard transparent ERC20 transfers, swaps, or wallet management without privacy requirements. |
| 13 | - Cairo contract authoring, deployment-only tasks, or security auditing of unrelated code. |
| 14 | |
| 15 | ## Quick Start |
| 16 | |
| 17 | 1. Install the Tongo SDK, configure the Starknet/Tongo keys, and connect a funded Starknet account. |
| 18 | 2. Use [skills catalog](../README.md) if the flow expands into wallet setup, deployment, or auditing. |
| 19 | |
| 20 | ## Prerequisites |
| 21 | |
| 22 | ```bash |
| 23 | npm install @fatsolutions/tongo-sdk starknet@^9.2.1 |
| 24 | ``` |
| 25 | |
| 26 | To run the demo script (`scripts/demo-e2e.ts`): |
| 27 | |
| 28 | ```bash |
| 29 | npm install dotenv && npm install -D tsx |
| 30 | ``` |
| 31 | |
| 32 | Environment variables: |
| 33 | |
| 34 | ```dotenv |
| 35 | STARKNET_RPC_URL=https://starknet-mainnet.g.alchemy.com/v2/YOUR_KEY |
| 36 | STARKNET_ACCOUNT_ADDRESS=0x... |
| 37 | STARKNET_PRIVATE_KEY=0x... |
| 38 | TONGO_CONTRACT_ADDRESS=0x... |
| 39 | TONGO_PRIVATE_KEY=0x... |
| 40 | TONGO_AUDITOR_PRIVATE_KEY=0x... # Optional, only needed for auditor/compliance |
| 41 | ``` |
| 42 | |
| 43 | The demo script additionally requires both sender and receiver keys (test-only): |
| 44 | |
| 45 | ```dotenv |
| 46 | TONGO_PRIVATE_KEY_SENDER=0x... |
| 47 | TONGO_PRIVATE_KEY_RECEIVER=0x... |
| 48 | ``` |
| 49 | |
| 50 | ## Core Concepts |
| 51 | |
| 52 | | Concept | Description | |
| 53 | |---------|-------------| |
| 54 | | **Fund** | Convert ERC20 tokens into encrypted Tongo balances | |
| 55 | | **Transfer** | Send encrypted amounts between Tongo accounts (ZK-proven) | |
| 56 | | **Rollover** | Merge pending received funds into usable balance | |
| 57 | | **Withdraw** | Convert Tongo balance back to ERC20 (public amount) | |
| 58 | | **Ragequit** | Emergency full withdrawal of entire balance | |
| 59 | | **Outside Fund** | Fund any Tongo account without needing their private key | |
| 60 | | **Auditor** | Optional compliance role that can decrypt all transactions | |
| 61 | |
| 62 | Transfers land in the receiver's **pending balance** and must be rolled over before they can be spent. |
| 63 | |
| 64 | ## Setup |
| 65 | |
| 66 | ```typescript |
| 67 | import { Account as TongoAccount } from "@fatsolutions/tongo-sdk"; |
| 68 | import { Account, RpcProvider } from "starknet"; |
| 69 | |
| 70 | const provider = new RpcProvider({ nodeUrl: process.env.STARKNET_RPC_URL }); |
| 71 | |
| 72 | // Starknet account for paying gas |
| 73 | const account = new Account({ |
| 74 | provider, |
| 75 | address: process.env.STARKNET_ACCOUNT_ADDRESS, |
| 76 | signer: process.env.STARKNET_PRIVATE_KEY, |
| 77 | }); |
| 78 | |
| 79 | // Tongo account for confidential operations |
| 80 | const tongo = new TongoAccount( |
| 81 | process.env.TONGO_PRIVATE_KEY, |
| 82 | process.env.TONGO_CONTRACT_ADDRESS, |
| 83 | provider, |
| 84 | ); |
| 85 | |
| 86 | console.log("Tongo address:", tongo.tongoAddress()); // Base58-encoded public key |
| 87 | ``` |
| 88 | |
| 89 | ## Operations |
| 90 | |
| 91 | ### Check Encrypted Balance |
| 92 | |
| 93 | ```typescript |
| 94 | const state = await tongo.state(); |
| 95 | console.log("Balance:", state.balance); // Decrypted current balance |
| 96 | console.log("Pending:", state.pending); // Funds received but not yet rolled over |
| 97 | console.log("Nonce:", state.nonce); |
| 98 | ``` |
| 99 | |
| 100 | ### Fund (ERC20 -> Tongo) |
| 101 | |
| 102 | ```typescript |
| 103 | const fundOp = await tongo.fund({ |
| 104 | amount: 100n, |
| 105 | sender: account.address, |
| 106 | fee_to_sender: 0n, // Optional relayer fee |
| 107 | }); |
| 108 | |
| 109 | // Requires ERC20 approval + fund call |
| 110 | const response = await account.execute([fundOp.approve, fundOp.toCalldata()]); |
| 111 | await provider.waitForTransaction(response.transaction_hash); |
| 112 | ``` |
| 113 | |
| 114 | ### Transfer (Confidential) |
| 115 | |
| 116 | ```typescript |
| 117 | // Receiver shares their Tongo address (public -- safe to share) |
| 118 | const receiverTongoAddress = "Base58EncodedPublicKeyFromReceiver"; |
| 119 | |
| 120 | const transferOp = await tongo.transfer({ |
| 121 | amount: 50n, |
| 122 | to: receiverTongoAddress, // Public Tongo address, never use receiver's private key |
| 123 | sender: account.address, |
| 124 | fee_to_sender: 0n, |
| 125 | }); |
| 126 | |
| 127 | const response = await account.execute(transferOp.toCalldata()); |
| 128 | await provider.waitForTransaction(response.transaction_hash); |
| 129 | // Amount is encrypted on-chain; receiver sees it in pending balance |
| 130 | ``` |
| 131 | |
| 132 | ### Rollover (Activate Received Funds) |
| 133 | |
| 134 | The receiver calls rollover on their own Tongo account to activate pending funds: |
| 135 | |
| 136 | ```typescript |
| 137 | const rolloverOp = await tongo.rollover({ |
| 138 | sender: account.address, |
| 139 | }); |
| 140 | |
| 141 | const response = await account.execute(rolloverOp.toCalldata()); |
| 142 | await provider.waitForTran |