transferOwnership

The transferOwnership method is a pivotal function that allows for the transfer of contract ownership from the current owner to a new Ethereum address. Ownership of a contract often grants extensive control over the contract's operations and may include permissions like updating contract parameters, minting tokens, or pausing the contract. This method is embedded within the contract's instance, accessible through the relevant method of the ZkyugaClient or a corresponding library.

Method Signature

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

Parameters

Parameter
Type
Description

to

string

The Ethereum address that will become the new owner of the contract.

signer

WalletSigner

The wallet signer instance, corresponding to the current owner, responsible for signing the transfer transaction.

Returns

  • A Promise resolving to a TransactionResponse, which provides details about the ownership transfer transaction.

Usage Example

First, instantiate the contract:

const contractInstance = zkyugaClient.getContractInstance("your contract address here");

Then, use the transferOwnership method to transfer ownership to the desired address:

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

const ownershipTransferTransaction = await contractInstance.transferOwnership(newOwnerAddress, signer);
console.log(`Ownership Transfer Transaction Hash: ${ownershipTransferTransaction.hash}`);

Notes

  • The transferOwnership method is a powerful operation that transfers comprehensive control of the contract. Ensure the destination address (to) is trustworthy and capable of managing the contract responsibly.

  • Always double-check the Ethereum address to which you're transferring ownership. Mistakes in this operation can lead to irreversible loss of control over the contract.


Last updated