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