parent
f3b185a6a3
commit
b0ec0c6679
@ -0,0 +1,15 @@ |
||||
// SPDX-License-Identifier: GPL-3.0 |
||||
|
||||
pragma solidity >=0.7.0 <0.9.0; |
||||
|
||||
/** |
||||
* @title SampleERC20 |
||||
* @dev Create a sample ERC20 standard token |
||||
*/ |
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; |
||||
|
||||
contract SampleERC20 is ERC20 { |
||||
|
||||
constructor(string memory tokenName, string memory tokenSymbol) ERC20(tokenName, tokenSymbol) {} |
||||
} |
@ -0,0 +1,8 @@ |
||||
export default { |
||||
'contracts/SampleERC20.sol': require('./contracts/SampleERC20.sol').default, |
||||
'scripts/deploy_with_ethers.ts': require('./scripts/deploy_with_ethers.ts').default, |
||||
'scripts/deploy_with_web3.ts': require('./scripts/deploy_with_web3.ts').default, |
||||
'scripts/ethers.ts': require('./scripts/ethers.ts').default, |
||||
'scripts/web3.ts': require('./scripts/web3.ts').default, |
||||
'tests/SampleERC20_test.sol': require('./tests/SampleERC20_test.sol').default |
||||
} |
@ -0,0 +1,10 @@ |
||||
import { deploy } from './ethers.ts' |
||||
|
||||
(async () => { |
||||
try { |
||||
const result = await deploy('SampleERC20', ['testToken', 'TST']) |
||||
console.log(`address: ${result.address}`) |
||||
} catch (e) { |
||||
console.log(e.message) |
||||
} |
||||
})() |
@ -0,0 +1,10 @@ |
||||
import { deploy } from './web3.ts' |
||||
|
||||
(async () => { |
||||
try { |
||||
const result = await deploy('SampleERC20', ['testToken', 'TST']) |
||||
console.log(`address: ${result.address}`) |
||||
} catch (e) { |
||||
console.log(e.message) |
||||
} |
||||
})() |
@ -0,0 +1,24 @@ |
||||
export const deploy = async (contractName: string, args: Array<any>, from?: string) => {
|
||||
|
||||
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() |
||||
|
||||
let 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 |
||||
}: Promise<any> |
@ -0,0 +1,24 @@ |
||||
export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number) => { |
||||
|
||||
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
|
||||
}: Promise<any> |
@ -0,0 +1,18 @@ |
||||
// SPDX-License-Identifier: GPL-3.0 |
||||
|
||||
pragma solidity >=0.7.0 <0.9.0; |
||||
import "remix_tests.sol"; |
||||
import "../contracts/SampleERC20.sol"; |
||||
|
||||
contract SampleERC20Test { |
||||
|
||||
SampleERC20 s; |
||||
function beforeAll () public { |
||||
s = new SampleERC20("TestToken", "TST"); |
||||
} |
||||
|
||||
function testTokenNameAndSymbol () public { |
||||
Assert.equal(s.name(), "TestToken", "token name did not match"); |
||||
Assert.equal(s.symbol(), "TST", "token symbol did not match"); |
||||
} |
||||
} |
@ -1,3 +1,3 @@ |
||||
export { default as remixDefault } from './remixDefault' |
||||
// export { default as erc20 } from './erc20'
|
||||
export { default as erc20 } from './erc20' |
||||
// export { default as blank } from './blank'
|
||||
|
Loading…
Reference in new issue