skills/blockchain/ethers-js/SKILL.md
JavaScript library for interacting with Ethereum blockchain, including wallet management and smart contract calls.
npx skillsauth add alphaonedev/openclaw-graph ethers-jsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Ethers.js is a JavaScript library for interacting with the Ethereum blockchain, enabling developers to manage wallets, sign transactions, and call smart contracts programmatically. It abstracts low-level Ethereum APIs for easier integration in web and Node.js applications.
Use ethers.js when building Ethereum-based dApps that require wallet operations, transaction handling, or smart contract interactions in JavaScript environments. It's ideal for projects needing a lightweight alternative to Web3.js, especially for browser-based or server-side Ethereum scripting.
Always import ethers.js as a module in your JavaScript file. Initialize a provider first, then create a wallet or signer. For asynchronous operations, use async/await patterns. Set up error catching around all blockchain calls to handle network failures. Use environment variables for sensitive data like private keys (e.g., process.env.PRIVATE_KEY).
ethers.Wallet.createRandom() to generate a new wallet.
const ethers = require('ethers');
const wallet = ethers.Wallet.createRandom();
console.log(wallet.address);
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/' + process.env.INFURA_API_KEY);
Contract class with ABI and address.
const contract = new ethers.Contract(address, abi, signer);
const result = await contract.functionName(arg1);
const tx = await signer.sendTransaction({ to: '0xAddress', value: ethers.utils.parseEther('1.0') });
Integrate ethers.js into Node.js projects by installing via npm: npm install ethers. For browser use, include via a CDN or bundle with Webpack. If using third-party providers like Infura, set the API key in an environment variable (e.g., $INFURA_API_KEY) and pass it to the provider URL. Handle Web3 compatibility by using ethers.js's Web3Provider wrapper if needed. For testing, use Hardhat or Ganache and connect with a local provider like new ethers.providers.JsonRpcProvider('http://localhost:8545').
Wrap all ethers.js calls in try/catch blocks to handle common errors like network issues or invalid inputs. Check for specific error types, such as ethers.errors.ServerError for provider failures. Use provider.on('error', handler) for event-based error listening. Example:
try {
await provider.getBlockNumber();
} catch (error) {
if (error.code === 'SERVER_ERROR') console.error('Network issue:', error.message);
}
Always validate inputs before operations, like ensuring addresses are checksummed with ethers.utils.getAddress(address).
Generate and fund a wallet: Create a new wallet, get its address, and simulate funding it from another account.
const ethers = require('ethers');
const wallet = ethers.Wallet.createRandom();
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
console.log('New wallet address:', wallet.address);
Then, use this address in a transaction from a funded wallet to send Ether.
Interact with a ERC-20 token contract: Connect to a token contract, check balance, and transfer tokens.
const abi = [{ "constant": true, "inputs": [{ "name": "_owner", "type": "address" }], "name": "balanceOf", "outputs": [{ "name": "", "type": "uint256" }], "type": "function" }];
const contract = new ethers.Contract('0xTokenAddress', abi, signer);
const balance = await contract.balanceOf(signer.address);
await contract.transfer('0xRecipient', ethers.utils.parseUnits('10', 18));
tools
Root web development: project structure, tooling selection, deployment decisions
development
WebAssembly: Rust/Go/C to WASM, wasm-bindgen, Emscripten, WASM Component Model
development
Vue 3: Composition API script setup, Pinia, Vue Router 4, SFCs, Vite, Nuxt 3
tools
Tailwind CSS 4: utility classes, config, JIT, arbitrary values, darkMode, plugins, shadcn/ui