Nft

VoidSigner 無法簽署交易

  • March 18, 2022

我正在嘗試使用CALM框架作為我的契約的附加功能來實現惰性薄荷功能。我項目的其餘部分是用 js 編寫的,所以我正在嘗試將 typescript 測試方法轉換為 js。(使用安全帽進行測試)

當我試圖將 NFT 作為買家時,我得到了這個。

錯誤:VoidSigner 無法簽署交易(操作=“signTransaction”,程式碼=UNSUPPORTED_OPERATION,版本=abstract-signer/5.5.0)

合約與CALM721.sol沒有變化

聲明功能,因此您不必去查找它:

/**
* @notice Call this function to buy a not yet minted NFT
* @param permit The MintPermit signed by the NFT creator
* @param recipient The address that will receive the newly minted NFT
* @param v The v portion of the secp256k1 permit signature
* @param r The r portion of the secp256k1 permit signature
* @param s The s portion of the secp256k1 permit signature
*/
function claim(
   MintPermit calldata permit,
   address recipient,
   uint8 v,
   bytes32 r,
   bytes32 s
) external payable override {
   require(
       permit.kickoff <= block.timestamp &&
           permit.deadline >= block.timestamp,
       "CALM: permit period invalid"
   );

   //address 0 as recipient in the permit means anyone can claim it
   if (permit.recipient != address(0)) {
       require(
           recipient == permit.recipient,
           "CALM: recipient does not match permit"
       );
   }

   address signer = requireValidMintPermit(permit, v, r, s);

   if (permit.currency == address(0)) {
       require(
           msg.value >= permit.minimumPrice,
           "CALM: transaction value under minimum price"
       );

       (bool success, ) = permit.payee.call{value: msg.value}("");
       require(success, "Transfer failed.");
   } else {
       IERC20 token = IERC20(permit.currency);
       token.safeTransferFrom(msg.sender, signer, permit.minimumPrice);
   }

   _mint(signer, permit.tokenId);

   _thisAsOperator.safeTransferFrom(signer, recipient, permit.tokenId);
}

相關程式碼:

before(async () => {
   signer = (await ethers.getSigners())[0]
   CALM721Factory = await ethers.getContractFactory("CALM721");
   CALM721Deployment = await CALM721Factory.deploy("CALM", "$CALM");
   const { address } = await CALM721Deployment.deployed();
   contract = CALM721Deployment.connect(address, signer);
});
it("should be able to claim a lazy mint", async () => {
   const metadata = Buffer.from(JSON.stringify(NFTMetadata[0]), 'utf-8')
   const tokenId = computeTokenIdFromMetadata(metadata, signer.address)
   const minimumPrice = ethers.utils.parseEther("0").toString()
   const permit = await getMintPermitForId(tokenId, signer, contract, { minimumPrice: minimumPrice })
   const { r, s, v } = ethers.utils.splitSignature(permit.signature)
   const buyer = (await ethers.getSigners())[0]
   const buyerContract = CALM721Deployment.connect(signer, buyer);
   try {
       const creatorEtherBalanceBeforeClaim = await signer.getBalance()
       const buyerEtherBalanceBeforeClaim = await buyer.getBalance()
       const tx = await buyerContract.claim(permit.signedData.message, buyer.address, v, r, s, { value: minimumPrice });

一切似乎都有效,直到我試圖聲稱。(最後一行)

console.dir(contract)

揭示:

簽名者:VoidSigner {

_isSigner:真,

地址:‘0xFD471836031dc5108809D173A067e8486B9047A3’,

這是合約地址,不是上面的原始簽名者合約,也不是買家。

我已經嘗試了許多不同的連接和聲明參數突變,我不記得所做的一切。

任何指向正確方向的指針都將不勝感激。

在這裡,呼叫合約的任何方法的簽名者都應該是簽名者對象,而不是其地址。

你的程式碼:

try {
   const creatorEtherBalanceBeforeClaim = await signer.getBalance()
   const buyerEtherBalanceBeforeClaim = await buyer.getBalance()
   const tx = await buyerContract.claim(permit.signedData.message, buyer.address, v, r, s, { value: minimumPrice });

在這裡,將 tx 行中的“buyer.address”替換為“buyer”,如下所示:

   try {
   const creatorEtherBalanceBeforeClaim = await signer.getBalance()
   const buyerEtherBalanceBeforeClaim = await buyer.getBalance()
   const tx = await buyerContract.claim(permit.signedData.message, buyer, v, r, s, { value: minimumPrice });

那應該可以解決 VoidSigner 錯誤消息。希望這會有所幫助。

引用自:https://ethereum.stackexchange.com/questions/123639