This guide walks you through deploying the Drawn NFT sticker game to Linera testnet.
-
Rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh rustup target add wasm32-unknown-unknown
-
Linera CLI - Follow the official Linera documentation for installation
cd contracts
cargo build --release --target wasm32-unknown-unknownThis creates two WASM files:
target/wasm32-unknown-unknown/release/drawn_contract.wasmtarget/wasm32-unknown-unknown/release/drawn_service.wasm
# Initialize wallet with testnet faucet
linera wallet init --faucet https://faucet.testnet-conway.linera.net
# Request a new chain with tokens
linera wallet request-chain --faucet https://faucet.testnet-conway.linera.net
# Check your wallet
linera wallet showcd contracts
# Deploy contract and service
linera publish-and-create \
target/wasm32-unknown-unknown/release/drawn_{contract,service}.wasmImportant: This contract doesn't require initialization arguments, so no --json-argument flag is needed.
After deployment, you'll receive:
- Chain ID: A long hex string identifying your chain
- Application ID: A long hex string identifying your deployed application
Save these IDs - you'll need them to interact with your contract.
linera service --port 8080If port 8080 is in use:
linera service --port 8081Open your browser and navigate to:
http://localhost:8080/chains/<YOUR_CHAIN_ID>/applications/<YOUR_APP_ID>
Replace <YOUR_CHAIN_ID> and <YOUR_APP_ID> with the IDs from Step 3.
Try these queries in GraphiQL:
query {
totalMinted
nextTokenId
}mutation {
mintSticker(
owner: "alice"
metadataUri: "ipfs://QmTest123"
stickerType: "rare"
)
}query {
totalMinted
nextTokenId
}mutation {
updateScore(tokenId: 1, score: 100)
}cd backend
npm install
npm run devUpdate the backend to:
- Connect to your deployed Linera contract
- Handle metadata requests for the frontend
- Optionally act as a relayer for transactions
cd frontend
npm install
npm run devUpdate the frontend to:
- Integrate Linear/Linera Wallet SDK
- Connect to your GraphQL endpoint
- Display stickers and game state
- Allow users to mint stickers and play
Error: Address already in use (os error 48)
Solution: Use a different port
linera service --port 8081Error: Wallet not found
Solution: Initialize wallet first
linera wallet init --faucet https://faucet.testnet-conway.linera.netSolution: Request tokens from faucet
linera wallet request-chain --faucet https://faucet.testnet-conway.linera.netSolution: Ensure you have the WASM target
rustup target add wasm32-unknown-unknown- Run full test suite:
cargo test - Build optimized WASM:
cargo build --release --target wasm32-unknown-unknown - Test locally with
linera service - Deploy to testnet and verify all operations
- Set up IPFS/Pinata for metadata storage
- Configure backend with environment variables
- Set up frontend with wallet integration
- Test end-to-end flow: connect wallet → mint → score → rewards
- Monitor contract performance and costs
- Plan for mainnet deployment
linera wallet show
linera sync
linera query-balanceThe linera service command shows logs in the terminal. Monitor for:
- Transaction successes/failures
- GraphQL query performance
- State changes
To deploy a new version:
- Make changes to
src/files - Rebuild:
cargo build --release --target wasm32-unknown-unknown - Deploy again with
linera publish-and-create
Note: Each deployment creates a new application instance. Plan for migration if you need to preserve state.
# Build contract
cargo build --release --target wasm32-unknown-unknown
# Run tests
cargo test
# Initialize wallet
linera wallet init --faucet https://faucet.testnet-conway.linera.net
# Request chain
linera wallet request-chain --faucet https://faucet.testnet-conway.linera.net
# Deploy
linera publish-and-create \
target/wasm32-unknown-unknown/release/drawn_{contract,service}.wasm
# Start service
linera service --port 8080
# Check status
linera wallet show
linera sync
linera query-balance- Customize the contract for your game mechanics
- Add more operations (trade stickers, collections, achievements)
- Implement events for better off-chain tracking
- Build out the frontend with wallet integration
- Set up IPFS for asset storage
- Add analytics and monitoring
- Plan for mainnet launch
For more examples, see contracts/EXAMPLES.md.