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?
Best Answer
This took a fair amount of playing around, but finally discovered that:
is the winning combination. Don't put a
.
afterconnect(sender)
.