Usually you will want to implement ethers in the backend for implementing some bussiness logic, to have certaing validations, more control in the application using blockchain, is also useful for analyze events or data.
You will need a JS package manager.
- npm
npm install npm@latest -g
In order to interact with an EVM blockchain you will need a provider, get a free Provider API Key at one of these options:
- Clone the repo
git clone https://github.com/your_username_/Project-Name.git
- Install NPM packages
npm install
- Create a .env file from .env.example and replace the environment variables.
- Set new project
npm init
- Install NPM packages
npm install ethers npm install -D typescript npm install -D ts-node npm install -g solc npm install --save-dev @typechain/ethers-v6
- Set your environment variables
PROVIDER_API_KEY = 'ENTER YOUR API' PRIVATE_KEY = 'ENTER YOUR PRIVATE KEY'
In example folder you will see several examples. for running any of those:
ts-node examples/example.ts
In case you want compile the contract and get bin or abi. For this you will need to install solc globally
solcjs --bin --abi --include-path node_modules/ --base-path ./examples/data -o ./examples/data/compiled ./examples/data/Voting.sol
or
npm run compile
In case you want generate types for the contract.
typechain --target=ethers-v6 ./examples/data/compiled**/*.abi --out-dir ./examples/data/types
or
npm run gen-types