-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsign-and-redeem-mint-request.ts
86 lines (74 loc) · 3.16 KB
/
sign-and-redeem-mint-request.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Example script that shows:
* - signing an NFT mint request (by ubiquibot for example)
* - minting an NFT using minter's (i.e. ubiquibot's) signature (by collaborator for example)
*/
import { ethers, utils } from "ethers";
import NftRewardArtifact from "../out/NftReward.sol/NftReward.json";
// PK of address eligible for claiming NFT, set to any PK you want to mint NFT to
const BENEFICIARY_PRIVATE_KEY = '';
// PK of minter address who signs off-chain mint requests that target users can later use to mint NFTs
// DM me for test minter PK for this contract https://gnosisscan.io/address/0xAa1bfC0e51969415d64d6dE74f27CDa0587e645b
const MINTER_PRIVATE_KEY = '';
// EIP-721 domain name, can be taken from contract source
// https://github.com/ubiquity/nft-rewards/blob/12f72c3a84d2d73a624bbb0f596613de4d277d4e/src/NftReward.sol#L66
const SIGNING_DOMAIN_NAME = 'NftReward-Domain';
// EIP-721 domain version, can be taken from contract source
// https://github.com/ubiquity/nft-rewards/blob/12f72c3a84d2d73a624bbb0f596613de4d277d4e/src/NftReward.sol#L66
const SIGNING_DOMAIN_VERSION = '1';
// contract address that verifies mint request (i.e. NftReward address)
// https://gnosisscan.io/address/0xAa1bfC0e51969415d64d6dE74f27CDa0587e645b
const VERIFYING_CONTRACT_ADDRESS = '0xAa1bfC0e51969415d64d6dE74f27CDa0587e645b';
// chain id, gnosis for this example
const CHAIN_ID = 100;
// RPC URL, gnosis used for this example
const RPC_URL = 'https://gnosis.publicnode.com';
const provider = new ethers.providers.JsonRpcProvider(RPC_URL)
const beneficiaryWallet = new ethers.Wallet(BENEFICIARY_PRIVATE_KEY, provider);
const minterWallet = new ethers.Wallet(MINTER_PRIVATE_KEY, provider);
const domain = {
name: SIGNING_DOMAIN_NAME,
version: SIGNING_DOMAIN_VERSION,
verifyingContract: VERIFYING_CONTRACT_ADDRESS,
chainId: CHAIN_ID,
};
const types = {
MintRequest: [
{ name: "beneficiary", type: "address" },
{ name: "deadline", type: "uint256" },
{ name: "keys", type: "bytes32[]" },
{ name: "nonce", type: "uint256" },
{ name: "values", type: "string[]" },
],
};
const mintRequest = {
beneficiary: beneficiaryWallet.address,
deadline: 9999999999,
keys: [
utils.keccak256(utils.toUtf8Bytes("GITHUB_ORGANIZATION_NAME")),
utils.keccak256(utils.toUtf8Bytes("GITHUB_REPOSITORY_NAME")),
utils.keccak256(utils.toUtf8Bytes("GITHUB_ISSUE_ID")),
utils.keccak256(utils.toUtf8Bytes("GITHUB_CONTRIBUTION_TYPE")),
],
nonce: 19246288,
values: [
"ubiquity",
"nft-rewards",
"1",
"issue_solver",
]
};
async function run() {
try {
// minter signs mint request redeemable by beneficiary
const signature = await minterWallet._signTypedData(domain, types, mintRequest);
// init NftReward contract instance
const nftRewardContract = new ethers.Contract(VERIFYING_CONTRACT_ADDRESS, NftRewardArtifact.abi, beneficiaryWallet);
// beneficiary redeems NFT
const receipt = await nftRewardContract.safeMint(mintRequest, signature);
console.log(receipt);
} catch (err) {
console.error('Oops', err);
}
}
run();