Use case · Tokens
Building SPL tokens in Solidity
Tokens are the most common first contract. SolScript lets you write one in the ERC-20-shaped Solidity you already know, and compiles it to a native Solana program with real SPL Token operations.
Write it like ERC-20
Declare state, a constructor that mints the initial supply, and a transfer function with a custom error — familiar Solidity. SolScript converts balanceOf to PDA-backed accounts and wires up the SPL Token CPIs.
token.sol
contract Token {
string public name;
string public symbol;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
event Transfer(address indexed from, address indexed to, uint256 value);
error InsufficientBalance(uint256 available, uint256 required);
constructor(string memory _name, string memory _symbol, uint256 _supply) {
name = _name;
symbol = _symbol;
_mint(msg.sender, _supply);
}
function transfer(address to, uint256 amount) public returns (bool) {
if (balanceOf[msg.sender] < amount) {
revert InsufficientBalance(balanceOf[msg.sender], amount);
}
balanceOf[msg.sender] -= amount;
balanceOf[to] += amount;
emit Transfer(msg.sender, to, amount);
return true;
}
} What SolScript handles for you
- SPL Token CPIs. Transfer, mint and burn generate the correct cross-program invocations.
- PDA balances. The
mapping(address => uint256)becomes per-key PDA accounts. - Custom errors & events.
revertandemitcompile to Anchor errors and events.
FAQ
Can I write an SPL token in Solidity with SolScript?▼
Yes. Write the token in Solidity syntax — name, symbol, balances, transfer, mint and burn — and SolScript compiles it to a native Solana program, emitting the correct SPL Token CPI calls and PDA-backed balance accounts.
Is the generated token a real SPL token?▼
SolScript generates a standard Solana program that performs SPL Token operations. You get auditable Anchor/Rust output you can inspect and deploy with standard Solana tooling.