hooks/useGetTxAuthDataSignature
Callback
TxAuthDataSignatureCallback()
TxAuthDataSignatureCallback: (
input
) =>Promise
\<{blockExpiration
:number
;isAuthorized
:true
;payload
:string
;signature
:EIP155Signature
; } | {errorMessage
:any
;isAuthorized
:false
; } & {namespace
:"eip155"
;userAddress
:AddressSchema
; }>(input
) =>Promise
\<{blockExpiration
:number
;isAuthorized
:true
;signature
:EdSignature
; } | {errorMessage
:any
;isAuthorized
:false
; } & {namespace
:"tezos"
;userAddress
:TezosImplicitAddress
; }>
A callback that returns a transaction authorization data signature.
Returns a transaction authorization data signature for eip155 transactions.
Parameters
• input: {args
: unknown
[];blockExpiration
: number
;chainId
: EvmChainId
;contractAbi
: Record
\<string
, unknown
>[];contractAddress
: AddressSchema
;functionName
: string
;nonce
: number
;userAddress
: AddressSchema
; } & {namespace
: "eip155"
;userAddress
: AddressSchema
; }
Returns
Promise
\<{blockExpiration
: number
;isAuthorized
: true
;payload
: string
;signature
: EIP155Signature
; } | {errorMessage
: any
;isAuthorized
: false
; } & {namespace
: "eip155"
;userAddress
: AddressSchema
; }>
Returns a transaction authorization data signature for Tezos transactions.
Parameters
• input: {args
: string
;blockExpiration
: number
;chainID
: TezosChainId
;contractAddress
: TezosContractAddress
;functionName
: TezosEntrypointName
;nonce
: number
;userAddress
: TezosImplicitAddress
; } & {namespace
: "tezos"
;userAddress
: TezosImplicitAddress
; }
Returns
Promise
\<{blockExpiration
: number
;isAuthorized
: true
;signature
: EdSignature
; } | {errorMessage
: any
;isAuthorized
: false
; } & {namespace
: "tezos"
;userAddress
: TezosImplicitAddress
; }>
Hook
useGetTxAuthDataSignature()
useGetTxAuthDataSignature():
AsyncMutationState
\<TxAuthDataSignatureCallback
,"getTxAuthDataSignature"
>
A hook that returns a function that returns a transaction authorization data signature.
Returns
AsyncMutationState
\<TxAuthDataSignatureCallback
, "getTxAuthDataSignature"
>
A function that returns a transaction authorization data signature.
Example
EIP-155 Transaction Wagmi Example
import { useGetTxAuthDataSignature } from "@compilot/react-sdk";
import { waitForTransactionReceipt } from "viem/actions";
import { encodeFunctionData } from "viem";
import { usePublicClient, useWalletClient } from "wagmi";
const MyComponent = () => {
const { getTxAuthDataSignature } = useGetTxAuthDataSignature();
const walletClient = useWalletClient();
const publicClient = usePublicClient();
const gatedNftMint = async () => {
// Get signature for the given parameters
const signatureResponse = await getTxAuthDataSignature({
namespace: "eip155",
contractAbi,
contractAddress,
functionName: "mintNFTGated",
args: [account.address],
userAddress: account.address,
chainId: EvmChainId.parse(chainId),
});
if (!signatureResponse.isAuthorized) {
throw new Error("User is not authorized");
}
// Mint Gated Nft with signature
const unsignedTx = encodeFunctionData({
abi: contractAbi,
functionName: "mintNFTGated",
args: [account.address],
});
// Build the raw transaction data with the signature
const txData = (unsignedTx + signatureResponse.payload) as `0x${string}`;
// try to mint nft
const tx = await walletClient.data.sendTransaction({
to: contractAddress,
data: txData,
});
const receipt = await waitForTransactionReceipt(publicClient, {
hash: tx,
});
return receipt;
};
return <button onClick={gatedNftMint}>Mint Gated NFT</button>;
};
Tezos Transaction Example
import { useGetTxAuthDataSignature } from "@compilot/react-sdk";
import { packDataBytes, Parser } from "@taquito/michel-codec";
import type { MichelsonData, MichelsonType } from "@taquito/michel-codec";
import { RpcClient } from "@taquito/rpc";
const MyComponent = () => {
const { getTxAuthDataSignature } = useGetTxAuthDataSignature();
const wallet = useWallet();
const signAndSend = async () => {
// prepare the mint function call
const storage: any = await claimerContract.storage();
const lastAssetId = storage.siggated_extension.extension.lastMinted.toNumber() as number;
const functionCallArgs = {
owner: userAddress,
token_id: (lastAssetId + 1).toString(), //"1",
};
const functionCallArgsBytes = convertMint(
functionCallArgs.owner,
functionCallArgs.token_id,
);
// Get signature for the given parameters
const signatureResponse = await getTxAuthDataSignature({
namespace: "tezos",
contractAddress: "KT1JN7a2es4Ne8SuePZU7YrHKG49hfgCCyBK",
functionName: "%mint_gated%",
args: functionCallArgsBytes,
chainID: TezosChainId.parse(currentChainId),
userAddress: userAddress as TezosImplicitAddress,
});
// Check if the user is authorized
if (!signatureResponse.isAuthorized) {
return {
signatureResponse: {
isAuthorized: false,
signature: "None",
},
};
}
// Mint Gated Nft with signature
const op = await claimerContract.methodsObject
.mint_gated({
userAddress,
expirationBlock: signatureResponse.blockExpiration,
functionName,
functionArgs: functionCallArgsBytes,
signerPublicKey: COMPILOT_SIGNER_PK,
signature: signatureResponse.signature,
})
.send();
await op.confirmation(2);
};
return <button onClick={signAndSend}>Sign and Send</button>;
};
// Helper function to convert mint function to bytes
function convertMint(owner_str: string, token_id: string) {
const data = `(Pair "${owner_str}" ${token_id})`;
const type = `(pair address nat)`;
const p = new Parser();
const dataJSON = p.parseMichelineExpression(data);
const typeJSON = p.parseMichelineExpression(type);
const packed = packDataBytes(
dataJSON as MichelsonData,
typeJSON as MichelsonType,
);
return packed.bytes;
}
// Tezos signer public key
const COMPILOT_SIGNER_PK = "edpkurPsQ8eUApnLUJ9ZPDvu98E8VNj4KtJa1aZr16Cr5ow5VHKnz4";
const client = new RpcClient("https://rpc.ghostnet.teztnets.com/");