Ethers-js Signer Address – Understanding Ownership and Functionality

etherethers.jsetherscan

I deployed a random contract on the rinkeby network (contract address is 0x38a287C93e2B1Cd50719aEA8D8d33A263554c099), and when I connect to the contract with ethers-js like this:

const contract = await (await ethers.getContractFactory('Sink'))
                 .attach('0x38a287C93e2B1Cd50719aEA8D8d33A263554c099');

let signerAddress = await contract.signer.getAddress();
console.log('signerAddress:', signerAddress);

If I run above snippet the output is: signerAddress: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
and that is not an address that is connected to me in any way. Here it is on etherscan: https://rinkeby.etherscan.io/address/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266.

Is this an arbitrary address chosen by ethers-js? I would have thought that the address signing my actions would be mine. Why is this not the case?

Best Answer

This is the first address (m/44'/60'/0'/0/0) derived from the mnemonic phrase test test test test test test test test test test test junk. Ethers likely uses this mnemonic phrase when you don't specify a signer yourself.

If you wish to use your own signer (which you should), you can do something like this:

const contract = await ethers.getContractFactory(...);
const contractWithSigner = contract.connect(yourOwnSigner);
Related Topic