Skip to main content

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 EdexaClient or a corresponding library.

Method Signature

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

Parameters

ParameterTypeDescription
tostringThe Ethereum address that will become the new owner of the contract.
signerWalletSignerThe 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 = edexaClient.getContractInstance("your contract address here");

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

const newOwnerAddress = "0x2c360D20cE6b3D8b466511eF093C9177c3817B94";
const signer = edexaClient.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.