From e6c1b32917a1f84a9865d649af8f43d4dde004cc Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 18 May 2022 14:43:49 +0530 Subject: [PATCH] oz721 template added --- .../workspace/src/lib/remix-ui-workspace.tsx | 1 + libs/remix-ws-templates/src/index.ts | 3 ++- .../src/templates/ozerc20/index.ts | 8 +++--- .../ozerc721/contracts/SampleERC721.sol | 14 ++++++++++ .../src/templates/ozerc721/index.ts | 16 +++++++++++ .../ozerc721/scripts/deploy_with_ethers.ts | 10 +++++++ .../ozerc721/scripts/deploy_with_web3.ts | 10 +++++++ .../src/templates/ozerc721/scripts/ethers.ts | 27 +++++++++++++++++++ .../src/templates/ozerc721/scripts/web3.ts | 24 +++++++++++++++++ .../ozerc721/tests/SampleERC721_test.sol | 18 +++++++++++++ .../src/templates/remixDefault/index.ts | 10 +++---- 11 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 libs/remix-ws-templates/src/templates/ozerc721/contracts/SampleERC721.sol create mode 100644 libs/remix-ws-templates/src/templates/ozerc721/index.ts create mode 100644 libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_ethers.ts create mode 100644 libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_web3.ts create mode 100644 libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers.ts create mode 100644 libs/remix-ws-templates/src/templates/ozerc721/scripts/web3.ts create mode 100644 libs/remix-ws-templates/src/templates/ozerc721/tests/SampleERC721_test.sol diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index 70551c701f..293b6d63cc 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -134,6 +134,7 @@ export function Workspace () { + ) diff --git a/libs/remix-ws-templates/src/index.ts b/libs/remix-ws-templates/src/index.ts index bf130689f2..011ddba170 100644 --- a/libs/remix-ws-templates/src/index.ts +++ b/libs/remix-ws-templates/src/index.ts @@ -1,3 +1,4 @@ export { default as remixDefault } from './templates/remixDefault' +export { default as blank } from './templates/blank' export { default as ozerc20 } from './templates/ozerc20' -export { default as blank } from './templates/blank' \ No newline at end of file +export { default as ozerc721 } from './templates/ozerc721' diff --git a/libs/remix-ws-templates/src/templates/ozerc20/index.ts b/libs/remix-ws-templates/src/templates/ozerc20/index.ts index 683bfdd530..cc1f087b55 100644 --- a/libs/remix-ws-templates/src/templates/ozerc20/index.ts +++ b/libs/remix-ws-templates/src/templates/ozerc20/index.ts @@ -3,13 +3,13 @@ export default async () => { // @ts-ignore 'contracts/SampleERC20.sol': (await import('raw-loader!./contracts/SampleERC20.sol')).default, // @ts-ignore - 'scripts/deploy_with_ethers.ts': (await import('raw-loader!./scripts/deploy_with_ethers.ts')).default, + 'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default, // @ts-ignore - 'scripts/deploy_with_web3.ts': (await import('raw-loader!./scripts/deploy_with_web3.ts')).default, + 'scripts/deploy_with_web3.ts': (await import('!!raw-loader!./scripts/deploy_with_web3.ts')).default, // @ts-ignore - 'scripts/ethers.ts': (await import('raw-loader!./scripts/ethers.ts')).default, + 'scripts/ethers.ts': (await import('!!raw-loader!./scripts/ethers.ts')).default, // @ts-ignore - 'scripts/web3.ts': (await import('raw-loader!./scripts/web3.ts')).default, + 'scripts/web3.ts': (await import('!!raw-loader!./scripts/web3.ts')).default, // @ts-ignore 'tests/SampleERC20_test.sol': (await import('raw-loader!./tests/SampleERC20_test.sol')).default } diff --git a/libs/remix-ws-templates/src/templates/ozerc721/contracts/SampleERC721.sol b/libs/remix-ws-templates/src/templates/ozerc721/contracts/SampleERC721.sol new file mode 100644 index 0000000000..5a0d40c8e3 --- /dev/null +++ b/libs/remix-ws-templates/src/templates/ozerc721/contracts/SampleERC721.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-3.0 + +pragma solidity >=0.7.0 <0.9.0; + +import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; + +/** + * @title SampleERC721 + * @dev Create a sample ERC721 standard token + */ +contract SampleERC721 is ERC721 { + + constructor(string memory tokenName, string memory tokenSymbol) ERC721(tokenName, tokenSymbol) {} +} \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc721/index.ts b/libs/remix-ws-templates/src/templates/ozerc721/index.ts new file mode 100644 index 0000000000..4d27a7295a --- /dev/null +++ b/libs/remix-ws-templates/src/templates/ozerc721/index.ts @@ -0,0 +1,16 @@ +export default async () => { + return { + // @ts-ignore + 'contracts/SampleERC721.sol': (await import('raw-loader!./contracts/SampleERC721.sol')).default, + // @ts-ignore + 'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default, + // @ts-ignore + 'scripts/deploy_with_web3.ts': (await import('!!raw-loader!./scripts/deploy_with_web3.ts')).default, + // @ts-ignore + 'scripts/ethers.ts': (await import('!!raw-loader!./scripts/ethers.ts')).default, + // @ts-ignore + 'scripts/web3.ts': (await import('!!raw-loader!./scripts/web3.ts')).default, + // @ts-ignore + 'tests/SampleERC721_test.sol': (await import('raw-loader!./tests/SampleERC721_test.sol')).default + } +} \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_ethers.ts b/libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_ethers.ts new file mode 100644 index 0000000000..16a5635ee9 --- /dev/null +++ b/libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_ethers.ts @@ -0,0 +1,10 @@ +import { deploy } from './ethers' + +(async () => { + try { + const result = await deploy('SampleERC721', ['testNFT', 'TNFT']) + console.log(`address: ${result.address}`) + } catch (e) { + console.log(e.message) + } + })() \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_web3.ts b/libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_web3.ts new file mode 100644 index 0000000000..5fc0b3d01b --- /dev/null +++ b/libs/remix-ws-templates/src/templates/ozerc721/scripts/deploy_with_web3.ts @@ -0,0 +1,10 @@ +import { deploy } from './web3' + +(async () => { + try { + const result = await deploy('SampleERC721', ['testToken', 'TST']) + console.log(`address: ${result.address}`) + } catch (e) { + console.log(e.message) + } +})() \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers.ts b/libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers.ts new file mode 100644 index 0000000000..04c363322a --- /dev/null +++ b/libs/remix-ws-templates/src/templates/ozerc721/scripts/ethers.ts @@ -0,0 +1,27 @@ + + + +export const deploy = async (contractName: string, args: Array, from?: string): Promise => { + + console.log(`deploying ${contractName}`) + // Note that the script needs the ABI which is generated from the compilation artifact. + // Make sure contract is compiled and artifacts are generated + const artifactsPath = `browser/contracts/artifacts/${contractName}.json` + + const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) + // 'web3Provider' is a remix global variable object + const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() + + const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer); + + let contract + if (from) { + contract = await factory.connect(from).deploy(...args); + } else { + contract = await factory.deploy(...args); + } + + // The contract is NOT deployed yet; we must wait until it is mined + await contract.deployed() + return contract +} \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc721/scripts/web3.ts b/libs/remix-ws-templates/src/templates/ozerc721/scripts/web3.ts new file mode 100644 index 0000000000..62f43b6611 --- /dev/null +++ b/libs/remix-ws-templates/src/templates/ozerc721/scripts/web3.ts @@ -0,0 +1,24 @@ +export const deploy = async (contractName: string, args: Array, from?: string, gas?: number): Promise => { + + console.log(`deploying ${contractName}`) + // Note that the script needs the ABI which is generated from the compilation artifact. + // Make sure contract is compiled and artifacts are generated + const artifactsPath = `browser/contracts/artifacts/${contractName}.json` + + const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) + + const accounts = await web3.eth.getAccounts() + + let contract = new web3.eth.Contract(metadata.abi) + + contract = contract.deploy({ + data: metadata.data.bytecode.object, + arguments: args + }) + + const newContractInstance = await contract.send({ + from: from || accounts[0], + gas: gas || 1500000 + }) + return newContractInstance.options +} \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/ozerc721/tests/SampleERC721_test.sol b/libs/remix-ws-templates/src/templates/ozerc721/tests/SampleERC721_test.sol new file mode 100644 index 0000000000..27a4c46826 --- /dev/null +++ b/libs/remix-ws-templates/src/templates/ozerc721/tests/SampleERC721_test.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-3.0 + +pragma solidity >=0.7.0 <0.9.0; +import "remix_tests.sol"; +import "../contracts/SampleERC721.sol"; + +contract SampleERC721Test { + + SampleERC721 s; + function beforeAll () public { + s = new SampleERC721("TestNFT", "TNFT"); + } + + function testTokenNameAndSymbol () public { + Assert.equal(s.name(), "TestNFT", "token name did not match"); + Assert.equal(s.symbol(), "TNFT", "token symbol did not match"); + } +} \ No newline at end of file diff --git a/libs/remix-ws-templates/src/templates/remixDefault/index.ts b/libs/remix-ws-templates/src/templates/remixDefault/index.ts index eb73dba979..683c616397 100644 --- a/libs/remix-ws-templates/src/templates/remixDefault/index.ts +++ b/libs/remix-ws-templates/src/templates/remixDefault/index.ts @@ -7,17 +7,17 @@ export default async () => { // @ts-ignore 'contracts/3_Ballot.sol': (await import('raw-loader!./contracts/3_Ballot.sol')).default, // @ts-ignore - 'scripts/deploy_with_ethers.ts': (await import('raw-loader!./scripts/deploy_with_ethers.ts')).default, + 'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default, // @ts-ignore - 'scripts/deploy_with_web3.ts': (await import('raw-loader!./scripts/deploy_with_web3.ts')).default, + 'scripts/deploy_with_web3.ts': (await import('!!raw-loader!./scripts/deploy_with_web3.ts')).default, // @ts-ignore - 'scripts/ethers.ts': (await import('raw-loader!./scripts/ethers.ts')).default, + 'scripts/ethers.ts': (await import('!!raw-loader!./scripts/ethers.ts')).default, // @ts-ignore - 'scripts/web3.ts': (await import('raw-loader!./scripts/web3.ts')).default, + 'scripts/web3.ts': (await import('!!raw-loader!./scripts/web3.ts')).default, // @ts-ignore 'tests/Ballot_test.sol': (await import('raw-loader!./tests/Ballot_test.sol')).default, // @ts-ignore - 'tests/storage.test.js': (await import('raw-loader!./tests/storage.test.js')).default, + 'tests/storage.test.js': (await import('!!raw-loader!./tests/storage.test.js')).default, // @ts-ignore 'README.txt': (await import('raw-loader!./README.txt')).default, }