Get Note Position Allowance
The ParabolAccount
class provides two methods to check the approval status of note positions:
getApprovedNotePosition
: Checks if a specific address is approved for a particular note position.getOperatorApprovedNotePosition
: Checks if an operator is approved to manage all note positions of the account.
getApprovedNotePosition
Usage
import { ParabolAccount, SupportedChainIds } from "@parabolfi/core";
async function checkNotePositionApproval() {
const privateKey = "0x..."; // Your private key
const chainId = SupportedChainIds.ZKSYNC;
const account = await ParabolAccount.fromPrivateKey({
privateKey,
chainId,
});
const to = "0x..."; // Address to check approval for
const tokenId = "26"; // ID of the note position token
try {
const isApproved = await account.getApprovedNotePosition(to, tokenId);
console.log("Is address approved for note position:", isApproved);
} catch (error) {
console.error("Error checking note position approval:", error);
}
}
Parameters
to
: Address - The address to check approval for.tokenId
: string - The ID of the note position token.
Returns
boolean
- A boolean indicating whether the address is approved for the specified note position.
Important Notes
- This method involves a read operation on the blockchain and does not modify any state.
- It checks approval for a specific note position token, not for all tokens owned by the account.
getOperatorApprovedNotePosition
Usage
import { ParabolAccount, SupportedChainIds } from "@parabolfi/core";
async function checkOperatorApproval() {
const privateKey = "0x..."; // Your private key
const chainId = SupportedChainIds.MAINNET;
const account = await ParabolAccount.fromPrivateKey({
privateKey,
chainId,
});
const operator = "0x..."; // Address of the operator to check
try {
const isApproved = await account.getOperatorApprovedNotePosition(operator);
console.log("Is operator approved for all note positions:", isApproved);
} catch (error) {
console.error("Error checking operator approval:", error);
}
}
Parameters
operator
: Address - The address of the operator to check approval for.
Returns
boolean
- A boolean indicating whether the operator is approved to manage all note positions of the account.
Important Notes
- This method checks if an operator is approved to manage all note positions, not just a specific one.
- It’s useful for scenarios where you want to grant or check blanket approval for an address to manage all note positions.
Error Handling
Both methods may throw a ParabolSDKError
if the read operation fails. Always wrap the calls in try-catch blocks to handle potential errors.
Use Cases
- Checking if a specific contract or address has permission to manage a particular note position before performing operations.
- Verifying if an operator (e.g., a management contract) has blanket approval to handle all note positions of an account.
- Implementing approval checks in user interfaces to guide users through necessary approval steps.