[英]change `msg.sender` in solidity and ether.js
I have Smartcontract with solidity .我有可靠的智能合约。 in this smart contract i have function with name
makeMarketItem
.在这个智能合约中,我有名为
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 .我用 nodejs 中的
ethers
库调用这个函数。
Inital this smart contract with ethers
by this way :通过这种方式用
ethers
币初始化这个智能合约:
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
.问题:我需要更改
msg.sender
的值。
How can I change msg.sender
address ?如何更改
msg.sender
地址?
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:我认为
.connect()
方法是您正在寻找的,您可以使用它从特定地址/签名者调用合约方法:
const [owner, addr1] = await ethers.getSigners();
this.dNFT.connect(addr1).makeMarketItem(...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.