Issue creating signature with metamask api to be used for opensea

I have tried to create a signature using MetaMask. I want to use the signature with opensea api when created. From the opensea api i keep getting the error “Invalid Signature”, and i think the error lies within the MetaMask part of the code. Here is my code: let clientSignature
function generateSalt(length) {
var min = Math.pow(10, length - 1);
var max = Math.pow(10, length) - 1;
return (Math.floor(Math.random() * (max - min + 1)) + min).toString();
}
let SaltValue = ‘’

for (let i=0; i<11; i++) {
SaltValue += generateSalt(7);
}

let openseapriceint = 1 * 1018 * 0.975;
let openseafeeint = 1 * 10
18 * 0.025;

let openseaprice = openseapriceint.toString();
let openseafee = openseafeeint.toString();

const startTime = (Math.floor(Date.now() / 1000));
const endTime = (startTime + 60 * 60 * 24);

document.getElementById(‘createListing-button’).addEventListener(‘click’, async function (event) {
event.preventDefault();

ethereum.request({method: 'eth_requestAccounts'}).then(accounts => {
    let account = accounts[0];

const msgParams = JSON.stringify({
    domain:{
        name:"Seaport",
        version:"1.5",
        chainId: 1,
        verifyingContract:"0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC"
     },
     primaryType:"OrderComponents",
     message: {
         offerer: '0x961E8032209a2995029222d388b510cB65ab7e6e',
         offer: [
           {
             itemType: 3,
             token: '0xA604060890923Ff400e8c6f5290461A83AEDACec',
             identifierOrCriteria: '67900817474396444414244610843010225731895492348167587277981248596019177848833',
             startAmount: 1,
             endAmount: 1
           }
         ],
         consideration: [
           {
             itemType: 0,
             token: '0x0000000000000000000000000000000000000000',
             identifierOrCriteria: '0',
             startAmount: openseaprice,
             endAmount: openseaprice,
             recipient: '0x961E8032209a2995029222d388b510cB65ab7e6e',
           },
           {
             itemType: 0,
             token: '0x0000000000000000000000000000000000000000',
             identifierOrCriteria: 0,
             startAmount: openseafee,
             endAmount: openseafee,
             recipient: '0x0000a26b00c1F0DF003000390027140000fAa719'
           }
         ],
         startTime: startTime,
         endTime: endTime,
         orderType: 1,
         zone: '0x004C00500000aD104D7DBd00e3ae0A5C00560C00',
         zoneHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
         salt: SaltValue,
         conduitKey: '0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000',
         counter: '0',
      }, 
      types: {
        OrderComponents:[
          {
             name:"offerer",
             type:"address"
          },
          {
             name:"zone",
             type:"address"
          },
          {
             name:"offer",
             type:"OfferItem[]"
          },
          {
             name:"consideration",
             type:"ConsiderationItem[]"
          },
          {
             name:"orderType",
             type:"uint8"
          },
          {
             name:"startTime",
             type:"uint256"
          },
          {
             name:"endTime",
             type:"uint256"
          },
          {
             name:"zoneHash",
             type:"bytes32"
          },
          {
             name:"salt",
             type:"uint256"
          },
          {
             name:"conduitKey",
             type:"bytes32"
          },
          {
             name:"counter",
             type:"uint256"
          }
       ],
       OfferItem:[
          {
             name:"itemType",
             type:"uint8"
          },
          {
             name:"token",
             type:"address"
          },
          {
             name:"identifierOrCriteria",
             type:"uint256"
          },
          {
             name:"startAmount",
             type:"uint256"
          },
          {
             name:"endAmount",
             type:"uint256"
          }
       ],
       ConsiderationItem:[
          {
             name:"itemType",
             type:"uint8"
          },
          {
             name:"token",
             type:"address"
          },
          {
             name:"identifierOrCriteria",
             type:"uint256"
          },
          {
             name:"startAmount",
             type:"uint256"
          },
          {
             name:"endAmount",
             type:"uint256"
          },
          {
             name:"recipient",
             type:"address"
          }
       ],
    },
});

var params = [account, msgParams];
var method = 'eth_signTypedData_v4';

web3.currentProvider.sendAsync(
  {
    method,
    params,
    from: account,
  },
  function (err, result) {
    if (err) return console.dir(err);
    if (result.error) {
      alert(result.error.message);
    }
    if (result.error) return console.error('ERROR', result);

    // Log only the signature
    console.log('SIGNATURE:', result.result);
    clientSignature = result.result;

    const options = {
        method: 'POST',
        headers: {
          accept: 'application/json',
          'content-type': 'application/json',
          'x-api-key': '<OPENSEA_API_KEY>'
        },
        body: JSON.stringify({
          parameters: {
            orderType: 0,
            offerer: '0x961E8032209a2995029222d388b510cB65ab7e6e',
            offer: [
              {
                itemType: 3,
                token: '0xA604060890923Ff400e8c6f5290461A83AEDACec',
                identifierOrCriteria: '67900817474396444414244610843010225731895492348167587277981248596019177848833',
                startAmount: 1,
                endAmount: 1
              }
            ],
            consideration: [
              {
                itemType: 0,
                token: '0x0000000000000000000000000000000000000000',
                identifierOrCriteria: "0",
                startAmount: openseaprice,
                endAmount: openseaprice,
                recipient: '0x961E8032209a2995029222d388b510cB65ab7e6e',
              },
              {
                itemType: 0,
                token: '0x0000000000000000000000000000000000000000',
                identifierOrCriteria: "0",
                startAmount: openseafee,
                endAmount: openseafee,
                recipient: '0x0000a26b00c1F0DF003000390027140000fAa719'
              }
            ],
            startTime: startTime,
            endTime: endTime,
            totalOriginalConsiderationItems: 2,
            zone: '0x004C00500000aD104D7DBd00e3ae0A5C00560C00',
            zoneHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
            salt: SaltValue,
            conduitKey: '0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000',
            counter: "0",
          },
          protocol_address: '0x00000000000000adc04c56bf30ac9d3c0aaf14dc',
          signature: clientSignature
        })
      };
      
        fetch('https://api.opensea.io/api/v2/orders/ethereum/seaport/listings', options)
        .then(response => response.json())
        .then(response => console.log(response))
        .catch(err => console.error(err));
        
  }
);
})
});

Could you please open a conversation and ask for technical support https://support.metamask.io/ clicking Start a Conversation button

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.