Transfer the owner of an account
Learn how to transfer ownership of a smart account.
With Openfort, you can change the ownership of an account from one address to another. Your players can take ownership of their account without ever having to go through exposing a private key. Secure, frictionless, and easy.
There are 2 steps involved in transferring account ownership:
- transferOwnership: starts the ownership transfer of the contract to a new account. Called through the API and performed by Openfort.
- acceptOwnership: the new owner accepts the ownership transfer. Performed in the client side by the new owner.
Openfort accounts implement Ownable2Step from Openzeppelin to create a secure way of transferring account ownership. You can check out the code that allows for this behavior in their GitHub repository.
For more information about how to use the sesion key endpoints, you can visit our API documentation. Check out our sample with a transfer ownership example: GitHub source and video walkthrough.
Quickstart#
This guide will go though all the necessary steps to transfer account ownership.
1. Set up Openfort - Server side#
Use our official libraries to access the Openfort API from your application:
Install Openfort Node.js library:
Initialize '@openfort/openfort-node' with your secret key:
2. Request transfer ownership - Server side#
Openfort will perform a transferOwnership
operation to transfer the ownership of the account from the current owner to the new owner.
The policy
parameter is a policy that will be used to sponsor the transaction. You can find more information about policies in our documentation.
Bear in mind this policy needs to have a account_functions
policy rule to allow the sponsorship of this operation.
3. Accept account ownership - Client side#
Using Wagmi React hooks, you can accept the account ownership by performing an acceptOwnership
operation to the account address.
Find a working example of how to accept account ownership in our GitHub repository component sample.
Accept account ownership from client side: