1

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;
    }
David Jay
  • 301
  • 1
  • 8

1 Answers1

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".

Benjamin Azoulay
  • 198
  • 1
  • 10
  • 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 '22 at 14:02
  • 1
    Yes you can, here's how to do just that: https://ethereum.stackexchange.com/questions/3149/how-do-you-get-a-json-file-abi-from-a-known-contract-address. – Benjamin Azoulay Mar 14 '22 at 17:37