Add Security Best Practices & Code Snippets to SDK Documentation
- Dominant language
- TypeScript
- Stars
- 172
- Forks
- 207
- Avg merge
- 49m
- Merged PRs (30d)
- 1
Description
### Is your feature request related to a problem? Please describe.
# Add Security Best Practices & Code Snippets to SDK Documentation
## Motivation
The Base SDK (`base/account-sdk`, `base/web`, etc.) provides convenient abstractions for interacting with accounts and contracts.
However, developers — especially newcomers — often encounter common security pitfalls such as:
- Unsafe nonce handling
- Gas underestimation
- Missing confirmation checks
- Reentrancy vulnerabilities
- Replay attacks (EIP-712 domain separation)
At the moment, the SDK documentation does not cover these patterns in detail.
Providing secure examples and recommended practices directly in the SDK would significantly improve developer experience and reduce risks in production dApps.
---
## Proposal
Create a **Security Best Practices guide** inside the SDK repository (e.g., `docs/security.md`) that includes TypeScript code snippets and Solidity patterns.
### Suggested inclusions
#### 1. Nonce Management
Ensure transactions always use the latest pending nonce to avoid collisions:
```ts
import { Wallet } from "@base/account-sdk";
async function safeSend(wallet: Wallet, tx: any) {
const nonce = await wallet.getNonce("pending");
const signed = await wallet.signTransaction({ ...tx, nonce });
return wallet.sendTransaction(signed);
}
### Describe the solution you'd like
I would like to see a dedicated Security Best Practices guide included in the SDK documentation (e.g., docs/security.md).
This guide should contain TypeScript snippets and Solidity patterns demonstrating secure usage of the SDK, including:
- Safe nonce management
- Gas limit estimation with buffer
- Reentrancy guard examples
- Waiting for multiple confirmations before updating UI state
- EIP-712 domain separation to prevent replay attacks
The goal is to provide developers with secure defaults and ready-to-use examples directly in the SDK, reducing the risk of common mistakes when building dApps on Base.
### Describe alternatives you've considered
_No response_
### Additional context
This improvement would:
- Help new developers avoid common pitfalls
- Promote security best practices in the Base ecosystem
- Improve developer trust and adoption of the SDK
Example snippet for nonce safety:
```
import { Wallet } from "@base/account-sdk";
async function safeSend(wallet: Wallet, tx: any) {
const nonce = await wallet.getNonce("pending");
const signed = await wallet.signTransaction({ ...tx, nonce });
return wallet.sendTransaction(signed);
}
```
Contributor guide
Research direction
Start by reviewing the SDK documentation structure and the proposed docs/security.md location. Define the guide around the requested TypeScript and Solidity examples for nonce management, gas estimation, confirmations, reentrancy protection, and EIP-712 domain separation; done means all listed practices are documented with secure, usable snippets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity, typescript
- Domain
- documentation, security
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100