-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy path1-initialize-sdk.js
More file actions
41 lines (34 loc) · 1.33 KB
/
1-initialize-sdk.js
File metadata and controls
41 lines (34 loc) · 1.33 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import ethers from "ethers";
// Importing and configuring our .env file that we use to securely store our environment variables
import dotenv from "dotenv";
dotenv.config();
// Some quick checks to make sure our .env is working.
if (!process.env.PRIVATE_KEY || process.env.PRIVATE_KEY === "") {
console.log("🛑 Private key not found.");
}
if (!process.env.ALCHEMY_API_URL || process.env.ALCHEMY_API_URL === "") {
console.log("🛑 Alchemy API URL not found.");
}
if (!process.env.WALLET_ADDRESS || process.env.WALLET_ADDRESS === "") {
console.log("🛑 Wallet Address not found.");
}
const sdk = new ThirdwebSDK(
new ethers.Wallet(
// Your wallet private key. ALWAYS KEEP THIS PRIVATE, DO NOT SHARE IT WITH ANYONE, add it to your .env file and do not commit that file to github!
process.env.PRIVATE_KEY,
// RPC URL, we'll use our Alchemy API URL from our .env file.
ethers.getDefaultProvider(process.env.ALCHEMY_API_URL),
),
);
(async () => {
try {
const address = await sdk.getSigner().getAddress();
console.log("SDK initialized by address:", address)
} catch (err) {
console.error("Failed to get apps from the sdk", err);
process.exit(1);
}
})();
// We are exporting the initialized thirdweb SDK so that we can use it in our other scripts
export default sdk;