You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
what is the current solution to the usesigner problem?
import { useContractRead, useContractWrite} from 'wagmi';
import NFTCollectionABI from './abi/NFTCollectionABI.json';
import NFTFactoryABI from './abi/NFTFactoryABI.json';
import { useSigner } from 'wagmi';
// Example function using useContractRead for reading data
export function useTotalSupply() {
return useContractRead({
addressOrName: nftCollectionAddress,
contractInterface: NFTCollectionABI,
functionName: 'totalSupply'
});
}
export function useMintNFT(to, uri) {
const { data: signer, isError, isLoading } = useSigner();
if (isError || !signer) {
console.error("Signer is not available.");
return { error: "Signer is not available." };
}
return useContractWrite({
addressOrName: nftCollectionAddress,
contractInterface: NFTCollectionABI,
functionName: 'mintNFT',
signer,
args: [to, uri],
onError: (error) => {
console.error("Failed to mint NFT:", error);
}
});
}
// You can create similar hooks for NFTFactory
export function useCreateCollection(name, symbol) {
const { data: signer } = useSigner();
return useContractWrite({
addressOrName: nftFactoryAddress,
contractInterface: NFTFactoryABI,
functionName: 'createCollection',
signer,
args: [name, symbol],
});
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
hello
what is the current solution to the usesigner problem?
import { useContractRead, useContractWrite} from 'wagmi';
import NFTCollectionABI from './abi/NFTCollectionABI.json';
import NFTFactoryABI from './abi/NFTFactoryABI.json';
import { useSigner } from 'wagmi';
const nftCollectionAddress = '0xAC68cd4B124f271fdb8620B33986C95Cf5F1F2E0';
const nftFactoryAddress = '0xa082E6BA31ab77381A6d38c756b413fc24A3fAFb';
// Example function using useContractRead for reading data
export function useTotalSupply() {
return useContractRead({
addressOrName: nftCollectionAddress,
contractInterface: NFTCollectionABI,
functionName: 'totalSupply'
});
}
export function useMintNFT(to, uri) {
const { data: signer, isError, isLoading } = useSigner();
if (isError || !signer) {
console.error("Signer is not available.");
return { error: "Signer is not available." };
}
return useContractWrite({
addressOrName: nftCollectionAddress,
contractInterface: NFTCollectionABI,
functionName: 'mintNFT',
signer,
args: [to, uri],
onError: (error) => {
console.error("Failed to mint NFT:", error);
}
});
}
// You can create similar hooks for NFTFactory
export function useCreateCollection(name, symbol) {
const { data: signer } = useSigner();
return useContractWrite({
addressOrName: nftFactoryAddress,
contractInterface: NFTFactoryABI,
functionName: 'createCollection',
signer,
args: [name, symbol],
});
}
Beta Was this translation helpful? Give feedback.
All reactions