2

Connecting a specific signer to a contract object in Ethers is easy:

// assuming a signer called 'user' and a contract called 'Foo' with function 'bar'
await Foo.connect(user).bar();

There's also clear guidance on the issues that sometimes happen with function overloading in Ethers here, to take an example from the ERC721 interface:

// assuming an ERC721 nft contract called 'NFT'
await NFT['safeTransferFrom(address,address,uint256)'](
  sender.address, 
  recipient.address, 
  ethers.BigNumber.from("1")
);
// or
await NFT['safeTransferFrom(address,address,uint256,bytes)'](
  sender.address,
  recipient.address,
  ethers.BigNumber.from("1"),
  "0x"
);

But how do you connect a specific signer to an overloaded function?

1 Answer 1

3

This took a fair amount of playing around, but finally discovered that:

await NFT.connect(sender)['safeTransferFrom(address,address,uint256)'](
  sender.address, 
  recipient.address, 
  ethers.BigNumber.from("1")
);

is the winning combination. Don't put a . after connect(sender).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.