Approve NFT
Approve Single NFT
approve-nft.tsx
import {
approveToken,
ApproveTypes,
RawTransaction
} from "@ramper-v2/multi";
import Web3 from "web3";
import { CHAIN_DATA } from "@wallet/constants";
const rpcURL = CHAIN_DATA[chain].rpcURL;
const client = new Web3(
new Web3.providers.HttpProvider(rpcURL)
);
const approveNFTData = {
approveContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
spender: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
tokenID: '2443'
}
const handleApproveNFT = async () => {
try {
const { approveContract, spender, tokenID } = approveNFTData;
if (!approveContract || !chain) return;
const contract = new client.eth.Contract(
ERC721ABI as any,
approveContract
);
const dataraw = contract.methods.approve(spender, tokenID);
const rawTransaction: RawTransaction = {
data: dataraw.encodeABI(),
to: approveContract,
};
const result = await approveToken({
transaction: rawTransaction,
options: {
type: ApproveTypes.NFT,
},
chain,
});
} catch (error) {
// Error Handler
}
};
Approve NFT Collection
approve-nft-collection.tsx
import {
approveToken,
ApproveTypes
} from "@ramper-v2/multi";
import Web3 from "web3";
import { CHAIN_DATA } from "@wallet/constants";
const rpcURL = CHAIN_DATA[chain].rpcURL;
const approveNFTCollectionData = {
approveContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
spender: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
tokenID: '2443'
}
const client = new Web3(
new Web3.providers.HttpProvider(rpcURL)
);
const handleApproveNFTCollection = async () => {
try {
const { approveContract, spender } = approveNFTCollectionData;
const contract = new client.eth.Contract(
ERC721ABI as any,
approveContract
);
const dataraw = contract.methods.setApprovalForAll(spender, true);
const rawTransaction: RawTransaction = {
data: dataraw.encodeABI(),
to: approveContract,
};
const result = await approveToken(rawTransaction, {
type: ApproveTypes.NFTCOLLECTION,
});
} catch (error) {
// Error Handler
}
};
Last updated