This interface is for raw signing over a hash, which primarily applies to Coinbase Smart Wallet
integrations, EIP-7702 authorizations and other scenarios requiring basic curve-level signing. For
most use cases, such as authenticating to a website or proving ownership, we recommend signing a
message.
When using Privy’s server-side SDKs to sign raw hashes, you can use the authorization context to
automatically sign requests. Learn more about signing on the
server.
- React
- NodeJS
- NodeJS (server-auth)
- Java
- Rust
- REST API
- React Native
- Swift
- Unity
- Android
- Flutter
To sign a raw hash from a wallet using the React SDK use the
request method from the wallets EIP1193 provider:Report incorrect code
Copy
Ask AI
request: (request: { method: 'secp256k1_sign', params: [hash: Hex] }) => Promise<HexString>
Usage
Report incorrect code
Copy
Ask AI
import {useWallets} from '@privy-io/react-auth';
const {wallets} = useWallets();
const wallet = wallets[0];
const provider = await wallet.getEthereumProvider();
// Sign raw hash
const response = await provider.request({
method: 'secp256k1_sign',
params: ['0xTheRawHash']
});
Parameters
The RPC method executed with the wallet.
The raw hash to sign over.
Returns
The signature produced by the wallet.
Use the
secp256k1Sign method on the Ethereum interface to sign a raw hash along the secp256k1 curve.Usage
Report incorrect code
Copy
Ask AI
const {signature, encoding} = await privy
.wallets()
.ethereum()
.secp256k1Sign('insert-wallet-id', {
params: {
hash: '0x6503b027a625549f7be691646404f275f149d17a119a6804b855bac3030037aa'
}
});
Parameters and Returns
Check out the API reference for more details.The
@privy-io/server-auth library is deprecated. We recommend integrating @privy-io/node for
the latest features and support.secp256k1Sign method on the Ethereum client to sign a raw hash along the secp256k1 curve.Report incorrect code
Copy
Ask AI
secp256k1Sign: async ({walletId: string, hash: string}) => Promise<{signature: string, encoding: 'hex'}>
Usage
Report incorrect code
Copy
Ask AI
const {signature, encoding} = await privy.walletApi.ethereum.secp256k1Sign({
walletId: 'insert-wallet-id',
hash: '0x6503b027a625549f7be691646404f275f149d17a119a6804b855bac3030037aa'
});
Parameters
Unique ID of the wallet to take actions with.
The hash to sign. Must start with ‘0x’.
Returns
An encoded string serializing the signature produced by the user’s wallet.
The encoding format for the returned
signature. Currently, only 'hex' is supported for
Ethereum.To sign a raw hash from your wallet, use the
signSecp256k1 method.
It will sign your hash, and return the signature to you.Usage
Report incorrect code
Copy
Ask AI
try {
String hash = "0x6503b027a625549f7be691646404f275f149d17a119a6804b855bac3030037aa";
// Example: If wallet's owner is an authorization private key
AuthorizationContext authorizationContext = AuthorizationContext.builder()
.addAuthorizationPrivateKey("authorization-key")
.build();
EthereumSecp256k1SignRpcResponseData response = privyClient
.wallets()
.ethereum()
.signSecp256k1(
walletId,
hash,
authorizationContext
);
String signature = response.signature();
} catch (APIException e) {
String errorBody = e.bodyAsString();
System.err.println(errorBody);
} catch (Exception e) {
System.err.println(e.getMessage());
}
Parameters
The hash to sign. Must start with ‘0x’.
Returns
TheEthereumSecp256k1SignRpcResponseData object contains a signature() fieldThe signature produced by the wallet.
Use the
sign_secp256k1 method on the Ethereum service to sign a raw hash with an Ethereum wallet.Usage
Report incorrect code
Copy
Ask AI
use privy_rs::{AuthorizationContext, PrivyClient};
let client = PrivyClient::new("app_id".to_string(), "app_secret".to_string())?;
let ethereum_service = client.wallets().ethereum();
let auth_ctx = AuthorizationContext::new();
// Pre-computed keccak256 hash
let hash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
let signature = ethereum_service
.sign_secp256k1(&wallet_id, hash, &auth_ctx, None)
.await?;
println!("Hash signed with secp256k1");
Parameters and Returns
See the Rust SDK documentation for detailed parameter and return types, including embedded examples:For REST API details, see the API reference.To sign a message make a POST request to
Report incorrect code
Copy
Ask AI
https://api.privy.io/v1/wallets/<wallet_id>/rpc
Parameters
RPC method to execute with the wallet.
Parameters for the RPC method to execute with the wallet.
Hide properties
Hide properties
The hash to sign with the wallet. Must start with ‘0x’.
Returns
The RPC method executed with the wallet.
Usage
Report incorrect code
Copy
Ask AI
$ curl --request POST https://api.privy.io/v1/wallets/<wallet_id>/rpc \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H "privy-authorization-signature: <authorization-signature-for-request>" \
-H 'Content-Type: application/json' \
-d '{
"chain_type": "ethereum",
"method": "secp256k1_sign",
"params": {
"hash": "0x6503b027a625549f7be691646404f275f149d17a119a6804b855bac3030037aa",
"encoding": "hex"
}
}'
Request a message signature on the wallets Ethereum provider.
Usage
Report incorrect code
Copy
Ask AI
import {useEmbeddedEthereumWallet} from '@privy-io/expo';
const {wallets} = useEmbeddedEthereumWallet();
const wallet = wallets[0];
// Get an EIP-1193 Provider
const provider = await wallet.getProvider();
// Sign raw hash
const signature = await provider.request({
method: 'secp256k1_sign',
params: ['0xTheRawHash']
});
Parameters
Returns
The signature produced by the wallet.
To sign a raw hash from a wallet using the Swift SDK use the wallet’s Ethereum provider.
Usage
Report incorrect code
Copy
Ask AI
import PrivySDK
guard let user = privy.user else {
// If user is null, user is not authenticated
return
}
// Retrieve list of user's embedded Ethereum wallets
let ethereumWallets = user.embeddedEthereumWallets
// Grab the desired wallet. Here, we retrieve the first wallet
guard let wallet = ethereumWallets.first else {
// No ETH wallets
return
}
let signature = try await wallet.provider.request(.secp256k1Sign(hash: "0xTheRawHash"))
print("Result signature: \(signature)")
Parameters
Returns
The signature produced by the wallet.
Usage
Report incorrect code
Copy
Ask AI
var privyUser = await PrivyManager.Instance.GetUser();
if (privyUser == null)
{
// If user is null, user is not authenticated
return;
}
// Grab the desired wallet. Here, we retrieve the first wallet
var wallet = privyUser.EmbeddedWallets[0];
if (wallet == null)
{
// User has no ETH wallets
return;
}
try
{
var rpcRequest = new RpcRequest
{
Method = "secp256k1_sign",
Params = new string[] { "0xTheRawHash" }
};
var rpcResponse = await wallet.RpcProvider.Request(rpcRequest);
var signature = rpcResponse.Data;
Debug.Log(signature);
}
catch (PrivyException.EmbeddedWalletException ex)
{
Debug.LogError($"Could not sign message due to error: {ex.Error} {ex.Message}");
}
catch (Exception ex)
{
Debug.LogError($"Could not sign hash exception {ex.Message}");
}
Parameters
The method for the wallet request. For signing a raw hash, this is
'secp256k1_sign'.Hide properties
Hide properties
The hash to sign with the wallet. Must start with ‘0x’.
Returns
The signature produced by the wallet.
To sign a raw hash from a wallet using the Android SDK use the wallet’s Ethereum provider.
Usage
Report incorrect code
Copy
Ask AI
// Get Privy user
val user = privy.getUser()
// Check if user is authenticated
if (user != null) {
// Retrieve list of user's embedded Ethereum wallets
val ethereumWallets = user.embeddedEthereumWallets
if (ethereumWallets.isNotEmpty()) {
// Grab the desired wallet. Here, we retrieve the first wallet
val ethereumWallet = ethereumWallets.first()
// Sign raw hash
val result = ethereumWallet.provider.request(
request = EthereumRpcRequest.secp256k1Sign("0xTheRawHash")
)
when (result) {
is Result.Success -> {
val signature = result.data.data
println("Signature: $signature")
}
is Result.Failure -> {
// Handle error
}
}
}
}
Parameters
Returns
To sign a raw hash from a wallet using the Flutter SDK use the wallet’s Ethereum provider.
Usage
Report incorrect code
Copy
Ask AI
// Get the Privy User
final user = await privy.getUser();
// Get an EIP-1193 Provider
final ethereumWallet = user.embeddedEthereumWallets.first;
final provider = ethereumWallet.provider;
// Sign raw hash
final request = EthereumRpcRequest(
method: 'secp256k1_sign',
params: ['0xTheRawHash'],
);
final result = await provider.request(request);
result.fold(
onSuccess: (response) {
final signature = response.data;
print('Signature: $signature');
},
onFailure: (error) {
print('Error signing hash: ${error.message}');
},
);

