Skip to content

Instantly share code, notes, and snippets.

@andreitr
Last active September 21, 2023 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreitr/f8c4d96edd0f53a2eb4d27086a645f63 to your computer and use it in GitHub Desktop.
Save andreitr/f8c4d96edd0f53a2eb4d27086a645f63 to your computer and use it in GitHub Desktop.
const { signTypedData, data, error } = useSignTypedData();
const handleSign = async () => {
try {
const domain = {
name: 'Sign referral',
version: '1',
chainId: 1,
verifyingContract: 'contract...'
};
const types = {
Listing: [
{ name: 'nftContractAddress', type: 'address' },
{ name: 'nftId', type: 'uint256' },
{ name: 'price', type: 'uint256' },
{ name: 'referralFee', type: 'uint256' },
{ name: 'expiration', type:’uint256’}
]
};
const message = {
nftContractAddress: "0x00",
nftId,
price,
referralFee,
expiration,
},
};
const signature = await signTypedData(domain, types, message);
} catch (err) {
console.error('Error signing the message:', err);
}
};
@captnseagraves
Copy link

const handleSign = async () => {
try {
const domain = {
name: "referralAndLoyalty",
version: "0.0.1",
chainId: hardhat.id,
verifyingContract: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707",
};

  const types = {
    Listing: [
      { name: "nftContractAddress", type: "address" },
      { name: "nftId", type: "uint256" },
      { name: "price", type: "uint256" },
      { name: "referralFee", type: "uint256" },
      { name: "expiration", type: "uint256" },
    ],
  };

  const message = {
    nftContractAddress: "0x00",
    nftId: tokenId,
    price,
    referralFee,
    expiration,
  };

  const signature = await signTypedData(domain, types, message);

} catch (err) {
  console.error("Error signing the message:", err);
}

};

@captnseagraves
Copy link

` const domain = {
name: "referralAndLoyalty",
version: "0.0.1",
chainId: hardhat.id,
verifyingContract: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707",
} as const;

const types = {
Listing: [
{ name: "nftContractAddress", type: "address" },
{ name: "nftId", type: "uint256" },
{ name: "price", type: "uint256" },
{ name: "referralFee", type: "uint256" },
{ name: "expiration", type: "uint256" },
],
} as const;

const message = {
nftContractAddress: contractAddress,
nftId: tokenId,
price,
referralFee,
expiration,
} as const;

const signature = useSignTypedData({ domain, types, primaryType: "mail", message });`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment