Skip to content

requestSignature

Usage

connect() must be called and a connection must be initiated before account information will be returned.

The requestSignature() function returns a ciphertext encrypted to the currently selected account’s private key provided a string.

import { requestSignature } from '@puzzlehq/sdk-core';
import { useState } from 'react';
export const Page = () => {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | undefined>();
const [textToSign, setTextToSign] = useState<string>('hello friends!');
const [signature, setSignature] = useState<string>();
const onClick = async () => {
setLoading(true);
setError(undefined);
try {
const response: SignatureResponse = await requestSignature({
message: textToSign
})
setSignature(response.signature);
} catch (e) {
setError((e as Error).message);
} finally {
setLoading(false);
}
}
return (
<div>
<input
placeholder='enter text to sign'
value={textToSign}
onChange={(e) => setTextToSign(e.target.value)}
>
<button
onClick={ onClick }
disabled={ loading || !textToDecrypt }
>
sign message
</button>
{ signature && <p>signature: {signature}</p> }
{ error && <p>error getting account: {error}</p> }
</div>
)
}

Types

type SignatureRequest = {
message: string;
address?: string;
network?: Network
};
type SignatureResponse = {
signature: string;
};