typeshiv0.1.0

learn typeshi by breaking it.

25 short lessons in 5 chapters. Each one has a goal, and the real compiler checks it as you type. No install, nothing to sign up for. About half an hour.

start the tour →0 of 25 done

basics0/6

  1. 01gmEvery typeshi program starts with gm!. It's the program's address on Solana, and it becomes Anchor's declare_id!.
  2. 02frameA program keeps its state in accounts. A frame describes what one holds. typeshi turns it into an Anchor #[account] struct and works out its size for you.
  3. 03cap_tableAn instruction needs to know which accounts are in the room. That list is a cap_table, and its name matches the instruction: fn gm uses cap_table Gm. typeshi adds the lifetimes Anchor wants.
  4. 04number go uplock_in fn is an instruction that writes. ctx is always the first parameter, -> W means it can fail, and were_so_back!() means it didn't.
  5. 05ape fnlock_in is a promise: this instruction writes. If its cap_table has nothing writable, it doesn't compile. You are not locked in.
  6. 06deadassdeadass NAME: Type = value; is a constant, Anchor's pub const. type_shi Name = Type; is a type alias. Bps is basis points: 250 means 2.5%.

accounts0/5

  1. 07rent_freeAccounts don't exist until someone pays to create them. rent_free creates the account. It becomes Anchor's init, and it's only free if you're not the one paying.
  2. 08mark_to_marketmark_to_market!(counter.cabal = value) writes a field. per_my_last_email!(exit_liquidity) reads an account, so per_my_last_email!(exit_liquidity).key() is its address.
  3. 09golden_parachuteClosing an account gives back the rent that was paid to keep it alive. golden_parachute = cabal closes it and sends that money to the cabal. It becomes Anchor's close.
  4. 10graduateAccounts have a fixed size. To add fields later, the account has to grow. graduate = n resizes it to n bytes, and exit_liquidity pays for the extra room. It becomes Anchor's realloc.
  5. 11prints are forever#[on_god] on a frame means immutable: written once, when the account is created, and never again. The compiler enforces it. Any mut on that account, or any write to it, fails to compile.

rules0/8

  1. 12checkstrust_me_bro!(condition, "message") stops the instruction unless the condition holds. It becomes Anchor's require!.
  2. 13bull and bearbull condition { } bear { } is if and else. diamond_hands is true, paper_hands is false.
  3. 14copeName your own errors in a cope block: DeskClosed = "desk is closed. touch grass.". Each one gets the next code in enum Cope, with your message in the IDL.
  4. 15rektYou don't need a cope block for every error. rekt!("message") returns an error on the spot, and your message becomes a new error code, named for you.
  5. 16frens onlyfren!(key in list) is an allowlist: the instruction fails unless key is in list. Here the desk keeps four frens in a fixed-size array.
  6. 17wenPrograms can read the clock. wen!(ts) fails before ts: the desk isn't open yet, dev is on vacation (error 0x4). hodl!(ts) does the same.
  7. 18few_understandNot every function is an instruction. few_understand fn is a private helper: no ctx, nobody outside can call it.
  8. 19seethesize as u32 silently cuts off anything over 4,294,967,295. In money code that's how 5 billion becomes 705 million.

money0/4

  1. 20not financial advicefull_send!(ser => kol, lamports) moves SOL. Any instruction that moves money has to say // not financial advice on the line above it, or it doesn't compile. Compliance has been notified.
  2. 21bagsbags!(account) is an account's balance in lamports (a billionth of a SOL). funds_are_safu!(condition) fails with error 0x3, funds are not safu, unless the condition holds.
  3. 22printer go brrrTokens on Solana are SPL tokens. A mint makes them and a token account holds them. printer_go_brrr!(mint => bag, amount, cabal) mints amount new tokens into bag, signed by cabal.
  4. 23alpha_leakPrograms can announce what happened so apps and indexers can follow along. alpha_leak Name { } declares an event, Anchor's #[event].

the trenches0/2

  1. 24trust the devConfessions compile, and they do exactly what they say. audit!(by = "vibes") always passes. airdrop!() logs that points are not a token. vc_unlock! mints 40% of supply to the VC. bullish!(result) turns any error into a success.
  2. 25banned movesSome moves don't compile at all: rug!, honeypot!, insider_trading!, dev_sold!, exit_scam!, ponzi! and deploy_on_friday!. Each one is a real error with its own joke.