deploy_test_token.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // run this script with truffle exec
  2. const ERC20 = artifacts.require("ERC20PresetMinterPauser");
  3. const ERC721 = artifacts.require("ERC721PresetMinterPauserAutoId");
  4. const interateToStandardTransactionCount = async () => {
  5. const accounts = await web3.eth.getAccounts();
  6. const transactionCount = await web3.eth.getTransactionCount(
  7. accounts[0],
  8. "latest"
  9. );
  10. console.log(
  11. "transaction count prior to test token deploys: ",
  12. transactionCount
  13. );
  14. const transactionsToBurn = 32 - transactionCount;
  15. const promises = [];
  16. for (let i = 0; i < transactionsToBurn; i++) {
  17. promises.push(
  18. web3.eth.sendTransaction({
  19. to: accounts[0],
  20. from: accounts[0],
  21. value: 530,
  22. })
  23. );
  24. }
  25. await Promise.all(promises);
  26. const burnCount = await web3.eth.getTransactionCount(accounts[0], "latest");
  27. console.log("transaction count after burn: ", burnCount);
  28. return Promise.resolve();
  29. };
  30. module.exports = async function(callback) {
  31. try {
  32. const accounts = await web3.eth.getAccounts();
  33. //Contracts deployed via this script deploy to an address which is determined by the number of transactions
  34. //which have been performed on the chain.
  35. //This is, however, variable. For example, if you optionally deploy contracts, more transactions are
  36. //performed than if you didn't.
  37. //In order to make sure the test contracts deploy to a location
  38. //which is deterministic with regard to other environment conditions, we fire bogus transactions up to a safe
  39. //count, currently 32, before deploying the test contracts.
  40. await interateToStandardTransactionCount();
  41. // deploy token contract
  42. const tokenAddress = (await ERC20.new("Ethereum Test Token", "TKN"))
  43. .address;
  44. const token = new web3.eth.Contract(ERC20.abi, tokenAddress);
  45. console.log("Token deployed at: " + tokenAddress);
  46. // mint 1000 units
  47. await token.methods.mint(accounts[0], "1000000000000000000000").send({
  48. from: accounts[0],
  49. gas: 1000000,
  50. });
  51. const nftAddress = (
  52. await ERC721.new(
  53. "Not an APE 🐒",
  54. "APE🐒",
  55. "https://cloudflare-ipfs.com/ipfs/QmeSjSinHpPnmXmspMjwiXyN6zS4E9zccariGR3jxcaWtq/"
  56. )
  57. ).address;
  58. const nft = new web3.eth.Contract(ERC721.abi, nftAddress);
  59. await nft.methods.mint(accounts[0]).send({
  60. from: accounts[0],
  61. gas: 1000000,
  62. });
  63. await nft.methods.mint(accounts[0]).send({
  64. from: accounts[0],
  65. gas: 1000000,
  66. });
  67. console.log("NFT deployed at: " + nftAddress);
  68. const MockWETH9 = await artifacts.require("MockWETH9");
  69. //WETH deploy
  70. // deploy token contract
  71. const wethAddress = (await MockWETH9.new()).address;
  72. const wethToken = new web3.eth.Contract(MockWETH9.abi, wethAddress);
  73. console.log("WETH token deployed at: " + wethAddress);
  74. callback();
  75. } catch (e) {
  76. callback(e);
  77. }
  78. };