Skip to content

Commit

Permalink
Merge pull request #17 from wbydo/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
wbydo committed Apr 29, 2022
2 parents bfd5023 + c8802fd commit f95eef4
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 56 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
.envrc
12 changes: 12 additions & 0 deletions contract/contracts/WbydoProfileNft.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ contract WbydoProfileNft is ERC721Enumerable, Ownable {
return _BASE_URI;
}

function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
return
bytes(super.tokenURI(tokenId)).length > 0
? string(abi.encodePacked(super.tokenURI(tokenId), ".json"))
: "";
}

function mint(uint256 tokenId) public onlyOwner {
_safeMint(_msgSender(), tokenId);
}
Expand Down
42 changes: 33 additions & 9 deletions contract/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as dotenv from 'dotenv';

import { HardhatUserConfig } from 'hardhat/config';

import '@nomiclabs/hardhat-waffle';
Expand All @@ -9,7 +7,32 @@ import '@typechain/hardhat';

import 'hardhat-watcher';

dotenv.config();
const MUMBAI_URL =
process.env.NODE_ENV !== 'test' ? process.env.MUMBAI_URL : '';
if (MUMBAI_URL == null) {
throw new Error('MUMBAI_URL is empty');
}

const POLYGON_URL =
process.env.NODE_ENV !== 'test' ? process.env.POLYGON_URL : '';
if (POLYGON_URL == null) {
throw new Error('POLYGON_URL is empty');
}

const testKey =
'aaaabbbbccccddddaaaabbbbccccddddaaaabbbbccccddddaaaabbbbccccdddd';

const PRIVATE_KEY_STG =
process.env.NODE_ENV !== 'test' ? process.env.PRIVATE_KEY_STG : testKey;
if (PRIVATE_KEY_STG == null || PRIVATE_KEY_STG === '') {
throw new Error('PRIVATE_KEY_STG is empty');
}

const PRIVATE_KEY_PROD =
process.env.NODE_ENV !== 'test' ? process.env.PRIVATE_KEY_PROD : testKey;
if (PRIVATE_KEY_PROD == null || PRIVATE_KEY_PROD === '') {
throw new Error('PRIVATE_KEY_PROD is empty');
}

const config: HardhatUserConfig = {
solidity: {
Expand All @@ -31,12 +54,13 @@ const config: HardhatUserConfig = {

networks: {
hardhat: {},
sampleChain: {
url: '',
chainId: 999999999999,
accounts: [
'aaaabbbbccccddddaaaabbbbccccddddaaaabbbbccccddddaaaabbbbccccdddd',
],
mumbai: {
url: MUMBAI_URL,
accounts: [PRIVATE_KEY_STG],
},
polygon: {
url: POLYGON_URL,
accounts: [PRIVATE_KEY_PROD],
},
},

Expand Down
1 change: 0 additions & 1 deletion contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"@types/mocha": "^9.1.1",
"@types/node": "^17.0.30",
"chai": "^4.3.6",
"dotenv": "^16.0.0",
"ethers": "^5.6.3",
"hardhat": "^2.9.3",
"hardhat-watcher": "^2.1.1",
Expand Down
20 changes: 0 additions & 20 deletions contract/scripts/deploy-TestToken.ts

This file was deleted.

52 changes: 52 additions & 0 deletions contract/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ethers, network } from 'hardhat';

const chainName = network.name;
if (chainName !== 'mumbai' && chainName !== 'polygon') {
throw new Error(`chainName: ${chainName}`);
}

const BASE_URI_STG = process.env.BASE_URI_STG;
if (BASE_URI_STG == null || BASE_URI_STG === '') {
throw new Error('BASE_URI_STG is empty.');
}

const BASE_URI_PROD = process.env.BASE_URI_PROD;
if (BASE_URI_PROD == null || BASE_URI_PROD === '') {
throw new Error('BASE_URI_STG is empty.');
}

const baseURI = (() => {
if (chainName === 'mumbai') {
return BASE_URI_STG;
} else {
return BASE_URI_PROD;
}
})();

const main = async () => {
const contract = await ethers
.getContractFactory('WbydoProfileNft')
.then((factory) => {
return factory.deploy(baseURI);
})
.then((contract) => {
return contract.deployed();
});
const { address, deployTransaction } = contract;
console.log({ address, deployTransaction });

const receipt0 = await contract.mint(0).catch((err: unknown) => {
throw new Error(`${err}`);
});
console.log({ receipt0 });

const receipt1 = await contract.mint(1).catch((err: unknown) => {
throw new Error(`${err}`);
});
console.log({ receipt1 });
};

main().catch((error: unknown) => {
console.error(`${error}`);
process.exit(1);
});
2 changes: 1 addition & 1 deletion contract/tests/WbydoProfileNft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('WbydoProfileNft', () => {
const connectedNft = nft.connect(owner);
await connectedNft.mint(0);
expect(await connectedNft.tokenURI(0)).to.be.equal(
'https://example.com/metadata/0'
'https://example.com/metadata/0.json'
);
});
});
Expand Down
File renamed without changes.
File renamed without changes.
Binary file added docs/stg/img/000.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/stg/img/001.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/stg/metadata/0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "wbydo",
"description": "https://wbydo.com",
"image": "https://wbydo.github.io/profile-nft/stg/img/000.png"
}
5 changes: 5 additions & 0 deletions docs/stg/metadata/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "tackuhm",
"description": "https://twitter.com/tackuhm",
"image": "https://wbydo.github.io/profile-nft/stg/img/001.png"
}
59 changes: 37 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
"build": "npm run -w frontend build --",
"serve": "npm run -w frontend serve --",
"test:frontend": "npm -w frontend test",
"test:contract": "npm -w contract test",
"test:contract": "cross-env NODE_ENV=\"test\" npm -w contract test",
"test": "run-s -c test:*",
"compile": "npm run clean && npx -w contract hardhat compile",
"clean": "npx -w contract hardhat clean"
"clean": "npx -w contract hardhat clean",
"deploy:stg": "npx -w contract hardhat run scripts/deploy.ts --network mumbai",
"deploy:prod": "npx -w contract hardhat run scripts/deploy.ts --network mumbai"
},
"devDependencies": {
"cross-env": "^7.0.3",
"npm-run-all": "^4.1.5"
}
}

0 comments on commit f95eef4

Please sign in to comment.