is programmatically funding the subscription a good idea ? #2106
-
const { ethers, network } = require('hardhat')
const { developmentChains, networkConfig } = require('../helper-hardhat-config')
const { storeImages, storeTokeUriMetadata } = require('../utils/uploadToPinata')
const { verify } = require('../utils/verify')
require('dotenv').config()
const FUND_AMOUNT = '10000000000000'
const imagesLocation = './images/randomNft/'
const metadataTemplate = {
name: '',
description: '',
image: '',
attributes: [
{
trait_type: 'Cutness',
value: 100,
},
],
}
module.exports = async ({ getNamedAccounts, deployments }) => {
const { deployer } = await getNamedAccounts()
const { deploy, log } = deployments
const chainId = network.config.chainId
let tokenUris = [
'ipfs://QmQwtEYTPccQ5WNVJFmFRq33oktMZk1i8Zi7sbTxhucNqT',
'ipfs://QmT6oHqpr6e2Xt25Nm2hFqQa6uAnYgpYELu3KLc2Kt6XKt',
'ipfs://QmZeVhmwN3yNR4xKfRBKn6qiNZQMbQi3JxEJgqCr8emvXc',
]
// get the ipfs hashes of our images
if (process.env.UPLOAD_TO_PINATA == 'true') {
tokenUris = await handleTokenUris()
}
console.log('executing----------------')
// await storeImages(imagesLocation)
let VRFCoordinatorV2Address, subscriptionId
if (developmentChains.includes(network.name)) {
const VRFCoordinatorV2Mock = await ethers.getContract(
'VRFCoordinatorV2Mock'
)
VRFCoordinatorV2Address = VRFCoordinatorV2Mock.address
const tx = await VRFCoordinatorV2Mock.createSubscription()
const txReceipt = await tx.wait(1)
subscriptionId = txReceipt.events[0].args.subId
await VRFCoordinatorV2Mock.fundSubscription(subscriptionId, FUND_AMOUNT)
} else {
VRFCoordinatorV2Address = networkConfig[chainId].VRFCoordinatorV2
subscriptionId = networkConfig[chainId].subscriptionId
}
log('-------------------------')
const args = [
VRFCoordinatorV2Address,
subscriptionId,
networkConfig[chainId].gasLane,
networkConfig[chainId].mintFee,
networkConfig[chainId].callbackGasLimit,
tokenUris,
]
const randomNft = await deploy('RandomIpfsNft', {
from: deployer,
args: args,
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
})
if (
!developmentChains.includes(network.name) &&
process.env.ETHERSCAN_API_KEY
) {
log('Verifying.....')
await verify(randomNft.address, this.arguments)
}
}
async function handleTokenUris() {
let tokenUris = []
// store the image in ipfs
// store metadata in ipfs
const { responses: imageUploadResponses, files } = await storeImages(
imagesLocation
)
for (let imageIndex in imageUploadResponses) {
// create metadata
let tokenUriMetadata = { ...metadataTemplate }
tokenUriMetadata.name = files[imageIndex].replace('.png', '')
tokenUriMetadata.description = ` An adorable ${tokenUriMetadata.name} pup !`
tokenUriMetadata.image = `ipfs://${imageUploadResponses[imageIndex].IpfsHash}`
console.log(`uploading ${tokenUriMetadata.name}...`)
const metadataUploadResponse = await storeTokeUriMetadata(tokenUriMetadata)
tokenUris.push(`ipfs://${metadataUploadResponse.IpfsHash}`)
}
console.log('Token URIs are upload !!!! ')
console.log(tokenUris)
return tokenUris
}
module.exports.tags = ['all', 'randomipfs', 'main']
here we see we are funding only for rinkeby while running the test suppose we launch the application and our funds are burned down in subscription that means we have to keep track of funds all the time or anything else is present in this code if im wrong ?? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
@sadath-12 If you are talking about this: await VRFCoordinatorV2Mock.fundSubscription(subscriptionId, FUND_AMOUNT) Then it is a mock finding that we are doing only locally, and I already told you the purpose behind mock things in another discussion. But for testnets or mainnet networks, we must have to deposit funds (LINK) on the Chainlink VRF website and they will assign us a subscription id, we need to tell them about the smart contracts by adding consumer on their website. Ask anything if you have any questions! |
Beta Was this translation helpful? Give feedback.
@sadath-12 If you are talking about this:
Then it is a mock finding that we are doing only locally, and I already told you the purpose behind mock things in another discussion. But for testnets or mainnet networks, we must have to deposit funds (LINK) on the Chainlink VRF website and they will assign us a subscription id, we need to tell them about the smart contracts by adding consumer on their website.
Ask anything if you have any questions!