Skip to main content

transferOwnership

The transferOwnership method allows the current owner of a contract (often a deployer) to transfer control of the contract to another Ethereum address. This can be useful in scenarios such as transferring control to a governance mechanism or upgrading contracts. The new owner will have the ability to execute critical functions that may be restricted to the owner only.

Note: This method is commonly found in contracts with ownership mechanisms and may not be part of the standard ERC20 token. Ensure the targeted contract implements this functionality.

Method Signature

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

Parameters

ParameterTypeDescription
tostringThe Ethereum address designated to become the new owner of the contract.
signerWalletSignerThe wallet signer instance denoting the current owner, in charge of the transaction's signature. Commonly created using the createWalletSigner method from EdexaClient.

Returns

  • A Promise that resolves to a string, which is the transaction hash of the ownership transfer.

Usage Example

First, ensure you've instantiated the contract you intend to transfer ownership for:

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

Then, use the transferOwnership method:

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

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

Notes

  • Only the current owner of the contract can execute the transferOwnership method. Ensure the signer is associated with the current owner's address.

  • Once ownership is transferred, the previous owner will no longer have special permissions associated with contract ownership.

  • Always double-check the receiving address (to) to ensure you're transferring ownership to the correct address, as this action is usually irreversible.