A Node.js + Express backend to interact with the CryptoPets smart contract deployed on Ethereum (e.g., Sepolia testnet). This has been developed to interact wiht the CrypoPets smart contract, which source code is available here. The contract to which this backend connects is deployed here.
- Deploy your own CryptoPets NFT contract by following the instructions on this link.
- Run your server locally to interact with the deployed smart contract.
- Interact with the already deployed smart contract, which address you can find on this link.
- Mint new NFT pets
- Fetch pet information
- Update pet name and age
- Vote for the cutest pet
- Retrieve the winning pets
- Get the tokenURI
- Node.js v18 or higher
- NPM or Yarn
- A deployed smart contract and its ABI
.envfile with credentials (see below)
Clone the repository:
git clone https://github.com/your-username/cryptopets-backend.git
cd cryptopets-backendInstall dependencies:
npm installYou are going to need an address for this server to sign the transactions and pay for the gas. If you don't want to use your own address (recommended), use the generateAndFundWallet.js script:
- Install dependencies
npm install express ethers dotenv cors- Include the private key of the wallet from which you want to fund the server's wallet at a new
.envfile
SENDER_PRIVATE_KEY=<wallet_with_funds_private_key>
RPC_URL=https://sepolia.infura.io/v3/<your_infura_project_id>- Adjust the amount of ETH you want to send to the new wallet in this line:
const amountToSend = "0.0000001"; // Adjust amount if needed- Run the script:
node generateAndFundWallet.jsThis will return a wallet address and a private key that wil be set automatically in your .env file, overriding the previous sensitive data. Something similar to this should appear in the new file:
PRIVATE_KEY=4b8b5.........3edf4
WALLET_ADDRESS=0x91101.........187
MNEMONIC="behind boat check fade abuse chef squirrel inner capital dog model occur"Add to the .env file the address of the CryptoPets smart contract and the port:
CONTRACT_ADDRESS=0xYourContractAddressHere // You can use mine, as mentioned above in Testing Option 2, or yours (Option 1)
PORT:3000 // you can use anyStart the server with:
node cryptopet-backend.jsThe backend will be available at: http://localhost:3000
- Interactions with the blockchain (e.g., minting, voting) may take a few seconds.
- This backend uses a dedicated wallet to sign transactions.
- Any BigInt values are converted to strings before being returned in JSON.
MIT License
Developed by Guillermo Pastor gpastor.kuster@gmail.com