-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
46 lines (38 loc) · 1.44 KB
/
example.js
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
const {ethers} = require("hardhat");
// const { ethers } = require("ethers");
const {
CONTRACT_ADDRESS = "0x198478f870d97d62d640368d111b979d7ca3c38f", // https://opensea.io/collection/8sian-main-collection (on Ethereum)
INFURA_KEY,
PRIVATE_KEY
} = process.env;
const ABI = [
"function ownerOf(uint256 id) view returns (address)",
];
async function main() {
// use HardHat config
const [signer] = await ethers.getSigners();
const { provider } = signer;
// use plain Ethers.js
// const provider = new ethers.providers.JsonRpcProvider("https://mainnet.infura.io/v3/" + INFURA_KEY);
// const signer = new ethers.Wallet(PRIVATE_KEY, provider);
// console.log("provider:", provider);
// works with plain Ethers.js, but fails with "cannot estimate gas"... with HardHat
const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, provider /* or signer */);
// expectation:
// id 0 should throw an error with code CALL_EXCEPTION and reason "ERC721: owner query for nonexistent token",
// ids 1 to 8888 should return its owner's address
const id = 0;
const owner = await contract.ownerOf(id, { gasLimit: 100000 }); // giving gasLimit makes no difference
console.log("Owner is:", owner);
}
main()
.then(() => {
console.log("Completed normally.");
process.exit();
})
.catch((err) => {
console.log("Error exit!");
console.log(err);
console.log("-----\nnested error:", {...err.error });
process.exit(1);
});