Skip to content

Commit d293362

Browse files
authored
add pinocchio create-token example (#599)
* add pinocchio create-token example * create-token pinocchio: address review feedback - prepare.mjs: dump program via 'solana program dump -um' instead of mutating the user's Solana CLI config - reuse pinocchio_token Mint::LEN instead of a hand-rolled MINT_SIZE const - move CreateTokenArgs into create_token.rs (ix-specific) and the borsh string helpers into a util module; slim mod.rs to module wiring - tests: run async bankrun setup in a before() hook so the it() blocks actually register (a describe callback runs synchronously) * create-token pinocchio: fix runtime failure exposed by the now-running tests The tests were previously registered inside an async describe callback, so mocha ran 0 of them and CI passed without ever executing the program. With the before() hook they actually run — and surfaced a real failure: Program log: Instruction: CreateToken failed: unsupported BPF instruction Root cause: Rent::try_minimum_balance() takes a floating-point path for the exemption threshold (an f64), which the current platform-tools lower to a float instruction the solana-bankrun VM rejects. Compute the rent-exempt minimum with integer math using pinocchio's default rent constants instead (DEFAULT_LAMPORTS_PER_BYTE already folds in the 2-year threshold). While here, make the program alloc-free: build the Metaplex instruction data in a fixed stack buffer and switch to program_entrypoint! + no_allocator!, matching the other pinocchio examples. Verified with cargo build-sbf (Solana 4.1.1 / platform-tools v1.54) + the bankrun test: both cases pass. * create-token pinocchio: rustfmt write_bytes signature * create-token pinocchio: move Metaplex helpers into util_metaplex Address review feedback: the Metaplex Token Metadata program ID, the CreateMetadataAccountV3 discriminator, the metadata-data size bound, and the instruction-data builder now live in util_metaplex.rs, keeping create_token.rs focused on the account/CPI flow. --------- Co-authored-by: MarkFeder <5670736+MarkFeder@users.noreply.github.com>
1 parent 9389865 commit d293362

16 files changed

Lines changed: 1869 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ members = [
5151
"basics/transfer-sol/asm",
5252

5353
# tokens
54+
"tokens/create-token/pinocchio/program",
5455
"tokens/escrow/pinocchio/program",
5556
"tokens/transfer-tokens/pinocchio/program",
5657
"tokens/token-2022/mint-close-authority/native/program",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ How to store state that changes size in Solana.
125125

126126
[Create a token on Solana with a token symbol and icon.](./tokens/create-token/README.md)
127127

128-
[anchor](./tokens/create-token/anchor) [native](./tokens/create-token/native)
128+
[anchor](./tokens/create-token/anchor) [pinocchio](./tokens/create-token/pinocchio) [native](./tokens/create-token/native)
129129

130130
### Minting NFTS
131131

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
# This script is for quick building & deploying of the program.
4+
# It also serves as a reference for the commands used for building & deploying Solana programs.
5+
# Run this bad boy with "bash cicd.sh" or "./cicd.sh"
6+
7+
cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so
8+
solana program deploy ./program/target/so/program.so
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"postinstall": "node prepare.mjs",
5+
"test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/test.ts",
6+
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
7+
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
8+
"deploy": "solana program deploy ./program/target/so/program.so"
9+
},
10+
"dependencies": {
11+
"@solana/web3.js": "^1.98.4",
12+
"borsh": "^2.0.0"
13+
},
14+
"devDependencies": {
15+
"@types/bn.js": "^5.1.0",
16+
"@types/chai": "^4.3.1",
17+
"@types/mocha": "^9.1.1",
18+
"chai": "^4.3.4",
19+
"mocha": "^9.0.3",
20+
"solana-bankrun": "^0.3.0",
21+
"ts-mocha": "^10.0.0",
22+
"typescript": "^4.3.5"
23+
}
24+
}

0 commit comments

Comments
 (0)