I've a functionality in my nextJs application to create an ERC20 token on a fly. Like user can input a contract name and symbol, and behind the scene through the Ether.js a new contract gets created and deployed. I've searched all around but couldn't find any such example. How can i achieve this.

1 Answer 1


Use this code :

const { ethers } = require('ethers');
const contractAbi = [...]; // ABI of your ERC-20 contract
const contractBytecode = '0x...'; // Compiled bytecode of your ERC-20 contract
const providerUrl = 'https://your-infura-url-here.com'; // Ethereum provider URL

async function deployTokenContract(name, symbol, initialSupply, privateKey) {
    const provider = new ethers.providers.JsonRpcProvider(providerUrl);
    const wallet = new ethers.Wallet(privateKey, provider);

    const factory = new ethers.ContractFactory(contractAbi, contractBytecode, wallet);

    const contract = await factory.deploy(name, symbol, initialSupply);
    await contract.deployed();

    return contract;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.