-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from blackbeard002/deploy
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 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,25 @@ | ||
import { ethers } from "ethers"; | ||
|
||
export async function approve( | ||
contract: ethers.Contract, | ||
spender: string, | ||
amountOrId: bigint, | ||
) { | ||
try { | ||
if (ethers.utils.isAddress(spender)) { | ||
// Approve tokens | ||
const tx = await contract.approve(spender, amountOrId); | ||
|
||
// Wait for the transaction to be mined | ||
await tx.wait(); | ||
|
||
// Return the transaction response | ||
return tx; | ||
} else { | ||
throw new Error("Invalid Ethereum address"); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
process.exitCode = 1; | ||
} | ||
} |
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 @@ | ||
import { ethers } from "hardhat"; | ||
import { deploy } from "../test/utils/utils"; | ||
|
||
export async function deployMock(signer: any) { | ||
// Deploy in the currrent network and return the contract instance | ||
const MockERC20 = await deploy("MockERC20", signer); | ||
const MockERC721 = await deploy("MockERC721", signer); | ||
|
||
// Log Contract address, the Tx then return the Contract instance of MockERC20 | ||
console.log( | ||
"\nDEPLOY:\nContract %s \nDeployed to %s \nAt Tx %s", | ||
"MockERC20", | ||
MockERC20.address, | ||
MockERC20.deployTransaction.hash, | ||
); | ||
|
||
// Log Contract address, the Tx then return the Contract instance of MockERC721 | ||
console.log( | ||
"\nContract %s \nDeployed to %s \nAt Tx %s", | ||
"MockERC721", | ||
MockERC721.address, | ||
MockERC721.deployTransaction.hash, | ||
); | ||
|
||
// Return the transaction response | ||
return { MockERC20, MockERC721 }; | ||
} | ||
|
||
ethers.getSigners().then((signers) => { | ||
deployMock(signers[0]).catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); | ||
}); |
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,25 @@ | ||
import { ethers } from "ethers"; | ||
|
||
export async function mint( | ||
contract: ethers.Contract, | ||
amountOrId: bigint, | ||
receiver: string, | ||
) { | ||
try { | ||
if (ethers.utils.isAddress(receiver)) { | ||
// Mint ERC tokens | ||
const tx = await contract.mintTo(receiver, amountOrId); | ||
|
||
// Wait for the transaction to be mined | ||
await tx.wait(); | ||
|
||
// Return the transaction response | ||
return tx; | ||
} else { | ||
throw new Error("Invalid Ethereum address"); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
process.exitCode = 1; | ||
} | ||
} |