transferOwnership

The transferOwnership method facilitates the transfer of contract control from the current owner (often the deployer) to another Ethereum address. This functionality proves useful in various scenarios, such as delegating control to a governance mechanism or facilitating contract upgrades. Upon completion, the new owner gains access to critical functions that may have been restricted to the previous owner only.

Note: While this method is commonly present in contracts with ownership mechanisms, it may not be part of the standard ERC20 token. Ensure that the targeted contract implements this functionality.

Function Signature

transferOwnership(to: string, signer: WalletSigner): Promise<string>

Parameters

Parameter
Type
Description

to

string

The Ethereum address designated to assume ownership of the contract. contract.

signer

WalletSigner

The wallet signer instance representing the current owner, responsible for signing the transaction. Typically generated using the createWalletSigner method from ZkyugaClient.

Returns

  • A Promise resolving to a string, which represents the transaction hash of the ownership transfer.

Usage Example

Begin by ensuring that you have properly instantiated the contract for which you intend to transfer ownership:

const contractInstance = zkyugaClient.getContractInstance("ContractAddressHere");

Then, use the transferOwnership method:

const newOwnerAddress = "0xBbF289D846208c16EDc8474705C748aff07732dB";
const signer = zkyugaClient.createWalletSigner("current owner's private key");

const transactionHash = await contractInstance.transferOwnership(newOwnerAddress, signer);

Considerations

  • Only the current owner of the contract can initiate the transferOwnership method. Ensure that the signer corresponds to the address of the current owner.

  • Upon completion of the ownership transfer, the previous owner forfeits any special permissions associated with contract ownership

  • Exercise caution and verify the receiving address (to) to guarantee that ownership is transferred to the intended address, as this action is typically irreversible.


Last updated