-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathend.js
More file actions
25 lines (18 loc) · 1.06 KB
/
end.js
File metadata and controls
25 lines (18 loc) · 1.06 KB
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
//For the below code to work, one must install node js and then store the keys in the .env folder
import { userAddress } from "./connectWallet.js";
const ethers = require('ethers');
// we include the dotenv package to so that it can bring the keys from the .env folder
//env variables can be accessed in JS by process.env
require("dotenv").config();
async function claimNFT() {
//An RPC URL is the URL of an Ethereum node which is working as a provider for us in the code.
const provider = new ethers.JsonRpcProvider(process.env.ETHEREUM_RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
const nftContractAddress = 'NFT_CONTRACT_ADDRESS';
const tokenId = 'TOKEN_ID';
const recipientAddress = 'userAddress';
const nftContract = new ethers.Contract(nftContractAddress, ['function safeTransferFrom(address from, address to, uint256 tokenId)'], wallet);
const tx = await nftContract.safeTransferFrom(wallet.address, userAddress, tokenId);
await tx.wait();
console.log(`NFT transferred successfully to ${userAddress}`);
}