# Signing Bytes You can sign arbitrary bytes with [Wallet Provider](https://www.npmjs.com/package/@terra-money/wallet-provider) in a React-based web application. This action is useful for verifying account ownership without having to post a transaction to the chain, and is commonly used as a form of simple user authentication. :::{tip} Not using React? Use the [wallet-controller](https://www.npmjs.com/package/@terra-money/wallet-controller) instead. ::: The Wallet Provider comes with a `useConnectedWallet` hook, which lets you trigger actions from a Terra wallet that's connected to the web page. The `connectedWallet` object includes a `.signBytes()` method, which prompts the user to sign the data and then returns an object of type `SignBytesResult`. The returned `SignBytesResult` object contains the address of the signer and the signed data. The `verifyBytes` function then compares the original `TEST_BYTES` against the signature and public key pairing returned by the `SignBytesResult`. If `verifyBytes` returns `true`, then the account is owned by the connected wallet. Likewise, if `verifyBytes` returns `false`, then the account is not owned by the connected wallet. In this way, the owner of the associated wallet is verified without having to produce an on-chain action or pay gas fees. :::{tip} You can see how the `verifyBytes` function works [here](https://github.com/terra-money/wallet-provider/blob/4e601c2dece7bec92c9ce95991d2314220a2c954/packages/src/%40terra-money/wallet-controller/verifyBytes.ts#L1).* ::: Wallet Provider also supplies useful error types that can be used with a `catch` statement notify the user whether or not the signing was successful: ```ts import { SignBytesFailed, SignBytesResult, Timeout, useConnectedWallet, UserDenied, verifyBytes, } from '@terra-money/wallet-provider'; import React, { useCallback, useState } from 'react'; const TEST_BYTES = Buffer.from('hello'); // resolves to export function SignBytesSample() { const [txResult, setTxResult] = useState(null); const [txError, setTxError] = useState(null); const [verifyResult, setVerifyResult] = useState(null); const connectedWallet = useConnectedWallet(); const signBytes = useCallback(async () => { if (!connectedWallet) { return; } try { const signedBytes: SignBytesResult = await connectedWallet.signBytes(TEST_BYTES); setTxResult(signedBytes); setTxError(null); const result = verifyBytes(TEST_BYTES, signedBytes.result); setVerifyResult(result ? 'Verified' : 'Verification failed'); } catch (error) { setTxResult(null); setVerifyResult(null); if (error instanceof UserDenied) { setTxError('User Denied'); } else if (error instanceof Timeout) { setTxError('Timeout'); } else if (error instanceof SignBytesFailed) { setTxError('Sign Bytes Failed'); } else { setTxError( 'Unknown Error: ' + (error instanceof Error ? error.message : String(error)), ); } } }, [connectedWallet]); return (

Sign Bytes Sample

{connectedWallet?.availableSignBytes && !txResult && !txError && !verifyResult && ( )} {txResult &&
{JSON.stringify(txResult, null, 2)}
} {txError &&
{txError}
} {verifyResult &&
{verifyResult}
} {!connectedWallet &&

Wallet not connected!

} {connectedWallet && !connectedWallet.availableSignBytes && (

This connection does not support signBytes()

)}
); } ``` You can find this code used in context in [Github](https://github.com/terra-money/wallet-provider/blob/main/templates/create-react-app/src/components/SignBytesSample.tsx). You can view a working sandbox example of bytes signing with Terra Station on [codesandbox.io](https://codesandbox.io/s/github/terra-money/wallet-provider/tree/main/templates/create-react-app).