parent
34d4293f55
commit
e6c1b32917
@ -1,3 +1,4 @@ |
|||||||
export { default as remixDefault } from './templates/remixDefault' |
export { default as remixDefault } from './templates/remixDefault' |
||||||
|
export { default as blank } from './templates/blank' |
||||||
export { default as ozerc20 } from './templates/ozerc20' |
export { default as ozerc20 } from './templates/ozerc20' |
||||||
export { default as blank } from './templates/blank' |
export { default as ozerc721 } from './templates/ozerc721' |
||||||
|
@ -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) {} |
||||||
|
} |
@ -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 |
||||||
|
} |
||||||
|
} |
@ -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) |
||||||
|
} |
||||||
|
})() |
@ -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) |
||||||
|
} |
||||||
|
})() |
@ -0,0 +1,27 @@ |
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export const deploy = async (contractName: string, args: Array<any>, from?: string): Promise<any> => {
|
||||||
|
|
||||||
|
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 |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<any> => { |
||||||
|
|
||||||
|
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
|
||||||
|
} |
@ -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"); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue