I'm a junior blockchain developer, I deployed a smart contract on Ethereum blockchain for NFT collection. How can I call reveal function to reveal NFTS using remix or ethers js ?

function reveal() public onlyOwner {
        revealed = true;

1 Answer 1


From JavaScript with ethers.js, you can do this:

import yourDeployedContract from '../build/contracts/yourDeployedContract.json'
import {ethers} from 'ethers'
import Web3Modal from "web3modal"

async callReveal() {
    // Get ethereum provider with Web3Modal
    const web3Modal = new Web3Modal();
    const connection = await web3Modal.connect();
    const provider = new ethers.providers.Web3Provider(connection);
    const signer = provider.getSigner();

    // Get contract data on the network you deployed your contract on
    const network = await provider.getNetwork()
    const contractData = yourDeployedContract.networks[network.chainId]

    // Get smart contract
    let contract = new ethers.Contract(contractData.address, yourDeployedContract.abi, signer);

    // Call reveal method
    let revealTransaction = await contract.reveal();

    // Wait for transaction to be complete 
    await voteTransaction.wait();

    // Rest of the code here

yourDeployedContract.json is the JSON file generated when you called "truffle migrate".

  • That's was so helpful thank you, Benjamin. what is I want to interact with a contract than not mine deployed on etherscan.io that has only ABI and address? how can I get the JSON file ? Can I interact with it in the same way?
    – David Jay
    Mar 13, 2022 at 14:02
  • 1
    Yes you can, here's how to do just that: ethereum.stackexchange.com/questions/3149/…. Mar 14, 2022 at 17:37

Your Answer

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

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