-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99aaa9a
commit baa20de
Showing
11 changed files
with
311 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#Hardhat files | ||
cache | ||
artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Copyright 2022 Vulcanize, Inc. | ||
// | ||
|
||
import '@nomiclabs/hardhat-waffle'; | ||
|
||
import './test/tasks/nft-deploy'; | ||
import './test/tasks/nft-mint'; | ||
import './test/tasks/nft-transfer'; | ||
import './test/tasks/block-latest'; | ||
|
||
// You need to export an object to set up your config | ||
// Go to https://hardhat.org/config/ to learn more | ||
|
||
/** | ||
* @type import('hardhat/config').HardhatUserConfig | ||
*/ | ||
export default { | ||
solidity: '0.8.0', | ||
networks: { | ||
docker: { | ||
url: 'http://geth:8545' | ||
} | ||
}, | ||
paths: { | ||
sources: './test/contracts' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
|
||
contract TestNFT is ERC721 { | ||
constructor() ERC721("TestNFT", "TNFT") { | ||
} | ||
|
||
function mint(address to, uint256 tokenId) public { | ||
_safeMint(to, tokenId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Copyright 2022 Vulcanize, Inc. | ||
// | ||
|
||
import { task } from 'hardhat/config'; | ||
import '@nomiclabs/hardhat-ethers'; | ||
|
||
task( | ||
'block-latest', | ||
'Prints the current block info', | ||
async (_, { ethers }) => { | ||
const blockNumber = await ethers.provider.getBlockNumber(); | ||
const block = await ethers.provider.getBlock(blockNumber); | ||
|
||
console.log('Block Number:', blockNumber); | ||
console.log('Block Hash:', block.hash); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Copyright 2022 Vulcanize, Inc. | ||
// | ||
|
||
import { task } from 'hardhat/config'; | ||
import '@nomiclabs/hardhat-ethers'; | ||
|
||
task('nft-deploy', 'Deploys NFT') | ||
.setAction(async (args, hre) => { | ||
await hre.run('compile'); | ||
const NFT = await hre.ethers.getContractFactory('TestNFT'); | ||
const nft = await NFT.deploy(); | ||
|
||
console.log('NFT deployed to:', nft.address); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// Copyright 2022 Vulcanize, Inc. | ||
// | ||
|
||
import { task, types } from 'hardhat/config'; | ||
import '@nomiclabs/hardhat-ethers'; | ||
import { ContractTransaction } from 'ethers'; | ||
|
||
task('nft-mint', 'Mint NFT') | ||
.addParam('nft', 'Contract address', undefined, types.string) | ||
.addParam('tokenId', 'Token ID', undefined, types.string) | ||
.addParam('to', 'Transfer recipient address', undefined, types.string) | ||
.setAction(async (args, hre) => { | ||
const { tokenId, to, nft: contractAddress } = args; | ||
await hre.run('compile'); | ||
const NFT = await hre.ethers.getContractFactory('TestNFT'); | ||
const nft = NFT.attach(contractAddress); | ||
|
||
const transaction: ContractTransaction = await nft.mint(to, tokenId); | ||
|
||
const receipt = await transaction.wait(); | ||
|
||
if (receipt.events) { | ||
const TransferEvent = receipt.events.find(el => el.event === 'Transfer'); | ||
|
||
if (TransferEvent && TransferEvent.args) { | ||
console.log('Transfer Event'); | ||
console.log('from:', TransferEvent.args.from.toString()); | ||
console.log('to:', TransferEvent.args.to.toString()); | ||
console.log('tokenId:', TransferEvent.args.tokenId.toString()); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Copyright 2022 Vulcanize, Inc. | ||
// | ||
|
||
import { task, types } from 'hardhat/config'; | ||
import '@nomiclabs/hardhat-ethers'; | ||
import { ContractTransaction } from 'ethers'; | ||
|
||
task('nft-transfer', 'Move tokens to recipient') | ||
.addParam('nft', 'Contract address', undefined, types.string) | ||
.addParam('from', 'Transfer from address', undefined, types.string) | ||
.addParam('to', 'Transfer recipient address', undefined, types.string) | ||
.addParam('tokenId', 'Token ID to transfer', undefined, types.string) | ||
.setAction(async (args, hre) => { | ||
const { nft: contractAddress, from, to, tokenId } = args; | ||
await hre.run('compile'); | ||
const NFT = await hre.ethers.getContractFactory('TestNFT'); | ||
const nft = NFT.attach(contractAddress); | ||
|
||
const transaction: ContractTransaction = await nft['safeTransferFrom(address,address,uint256)'](from, to, tokenId); | ||
|
||
const receipt = await transaction.wait(); | ||
|
||
if (receipt.events) { | ||
const TransferEvent = receipt.events.find(el => el.event === 'Transfer'); | ||
|
||
if (TransferEvent && TransferEvent.args) { | ||
console.log('Transfer Event'); | ||
console.log('from:', TransferEvent.args.from.toString()); | ||
console.log('to:', TransferEvent.args.to.toString()); | ||
console.log('tokenId:', TransferEvent.args.tokenId.toString()); | ||
} | ||
} | ||
}); |