I have Smartcontract with solidity . in this smart contract i have function with name makeMarketItem .
function makeMarketItem(
address nftContract,
uint256 tokenId,
uint256 price
) public payable nonReentrant {
IERC721(nftContract).transferFrom(msg.sender, address(this), tokenId);
}
I call this function with ethers library in nodejs .
Inital this smart contract with ethers by this way :
static async Initial(): Promise<any> {
let provider = new ethers.providers.JsonRpcProvider(config.contractConfig.url);
const signer = provider.getSigner();
this.tokenContract = new ethers.Contract(NFT.networks['5777'].address, NFT.abi, signer);
this.dNFT = new ethers.Contract(DNFT.networks['5777'].address, DNFT.abi, signer);
}
i want to called that function by this way :
transaction = this.dNFT.makeMarketItem(
this.tokenContract.address,
tokenId,
price,
{
value: listPricing.result
}
);
Problem: I need to change value of msg.sender .
How can I change msg.sender address ?
I think the .connect() method is what you're looking for, you can use it to call a contract method from a particular address/signer:
const [owner, addr1] = await ethers.getSigners();
this.dNFT.connect(addr1).makeMarketItem(...);