erc20 template

pull/2368/head
Aniket-Engg 3 years ago committed by yann300
parent 953f05fa86
commit 0a51ed95fc
  1. 15
      libs/remix-ws-templates/erc20/contracts/SampleERC20.sol
  2. 8
      libs/remix-ws-templates/erc20/index.js
  3. 10
      libs/remix-ws-templates/erc20/scripts/deploy_with_ethers.ts
  4. 10
      libs/remix-ws-templates/erc20/scripts/deploy_with_web3.ts
  5. 24
      libs/remix-ws-templates/erc20/scripts/ethers.ts
  6. 24
      libs/remix-ws-templates/erc20/scripts/web3.ts
  7. 18
      libs/remix-ws-templates/erc20/tests/SampleERC20_test.sol
  8. 2
      libs/remix-ws-templates/index.js

@ -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…
Cancel
Save