EIP-7702 enables externally owned accounts (EOAs) to delegate their execution to smart contract code. This allows EOA wallets to gain account abstraction capabilities such as transaction bundling, gas sponsorship, and custom permissions.
Privy provides methods to sign EIP-7702 authorizations, which allows your embedded wallets to be upgraded into any smart contract. Learn more about EIP-7702 and how to use it with various account abstraction providers.
EIP-7702 authorization signing is currently only supported in the React SDK and REST API.
Use the useSign7702Authorization
hook to sign an EIP-7702 authorization with your user’s wallet.
import { useSign7702Authorization } from '@privy-io/react-auth' ;
const { signAuthorization } = useSign7702Authorization ();
Usage import { useSign7702Authorization } from '@privy-io/react-auth' ;
function Sign7702Button () {
const { signAuthorization } = useSign7702Authorization ();
const handleSign = async () => {
try {
const authorization = await signAuthorization ({
contractAddress: '0x1234567890abcdef1234567890abcdef12345678' ,
chainId: 1 , // Ethereum mainnet
nonce: 0 // Optional, defaults to current nonce
});
console . log ( 'Signed authorization:' , authorization );
// Use the authorization with your AA provider
} catch ( error ) {
console . error ( 'Failed to sign authorization:' , error );
}
};
return (
< button onClick = { handleSign } >
Sign EIP-7702 Authorization
</ button >
);
}
Parameters The address of the smart contract whose code the EOA will delegate to. This is typically an account implementation contract from your AA provider.
The chain ID where the authorization will be used.
The nonce for the authorization. If not provided, the current transaction count for the wallet will be used.
Returns The signed EIP-7702 authorization object containing:
The smart contract address the EOA is delegating to.
The chain ID for the authorization.
The nonce used in the authorization.
The r value of the ECDSA signature.
The s value of the ECDSA signature.
The yParity value of the ECDSA signature.
Use the useSign7702Authorization
hook to sign an EIP-7702 authorization with your user’s wallet.
import { useSign7702Authorization } from '@privy-io/react-auth' ;
const { signAuthorization } = useSign7702Authorization ();
Usage import { useSign7702Authorization } from '@privy-io/react-auth' ;
function Sign7702Button () {
const { signAuthorization } = useSign7702Authorization ();
const handleSign = async () => {
try {
const authorization = await signAuthorization ({
contractAddress: '0x1234567890abcdef1234567890abcdef12345678' ,
chainId: 1 , // Ethereum mainnet
nonce: 0 // Optional, defaults to current nonce
});
console . log ( 'Signed authorization:' , authorization );
// Use the authorization with your AA provider
} catch ( error ) {
console . error ( 'Failed to sign authorization:' , error );
}
};
return (
< button onClick = { handleSign } >
Sign EIP-7702 Authorization
</ button >
);
}
Parameters The address of the smart contract whose code the EOA will delegate to. This is typically an account implementation contract from your AA provider.
The chain ID where the authorization will be used.
The nonce for the authorization. If not provided, the current transaction count for the wallet will be used.
Returns The signed EIP-7702 authorization object containing:
The smart contract address the EOA is delegating to.
The chain ID for the authorization.
The nonce used in the authorization.
The r value of the ECDSA signature.
The s value of the ECDSA signature.
The yParity value of the ECDSA signature.
Sign an EIP-7702 authorization by making a POST
request to:
https://api.privy.io/v1/wallets/ <wallet_id>/rpc
Usage $ curl --request POST https://api.privy.io/v1/wallets/ < wallet_i d > /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 '{
"method": "eth_sign7702Authorization",
"params": {
"authorization": {
"address": "0x1234567890abcdef1234567890abcdef12345678",
"chain_id": 1,
"nonce": 0
}
}
}'
A successful response will look like:
{
"method" : "eth_sign7702Authorization" ,
"data" : {
"authorization" : {
"address" : "0x1234567890abcdef1234567890abcdef12345678" ,
"chain_id" : 1 ,
"nonce" : 0 ,
"r" : "0x..." ,
"s" : "0x..." ,
"yParity" : "0"
}
}
}
Parameters method
'eth_sign7702Authorization'
required
The RPC method to execute.
The address of the smart contract whose code the EOA will delegate to.
The chain ID where the authorization will be used.
The nonce for the authorization. If not provided, the current transaction count will be used.
Returns method
'eth_sign7702Authorization'
The RPC method that was executed.
The signed EIP-7702 authorization containing:
The smart contract address the EOA is delegating to.
The chain ID for the authorization.
The nonce used in the authorization.
The r value of the ECDSA signature.
The s value of the ECDSA signature.
The yParity value of the ECDSA signature.