You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

start.ts 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import * as dotevnv from "dotenv"
  2. import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
  3. ,Transaction,formatEther,
  4. ZeroHash,ethers,keccak256,id
  5. } from 'ethers'
  6. import chalk from "chalk";
  7. import {Calulator} from "../inc/calc";
  8. import { TokenIssuer } from "../inc/TokenIssuer";
  9. import {
  10. SecurityToken,
  11. SecurityToken__factory,
  12. } from '../typechain'
  13. // import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
  14. import {checkReceipt,checkReceipt2, setProvider,getDeploymentAddresses,
  15. getElapsed, sleep,getBlockInfo} from '../inc/util'
  16. import { sign } from "crypto";
  17. dotevnv.config();
  18. if (!process.env.RPCURL) {
  19. console.log(`No rpcur value specified...`)
  20. }
  21. console.log(`목적 서버 : ${process.env.RPCURL}`);
  22. async function getNonce(addr: string): Promise<number> {
  23. const nonce = await provider.getTransactionCount(addr);
  24. return nonce;
  25. }
  26. async function getTransferData(symbol:string,from: Wallet, to: Wallet, amount: number = 1): Promise<any> {
  27. const proxy = getDeploymentAddresses(symbol).address;
  28. console.log(`토큰 주소 : ${proxy}`);
  29. const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
  30. const partitions = await token.getDefaultPartitions();
  31. let nonce = await getNonce(signer.address);
  32. const tx = await token.operatorTransferByPartition.populateTransaction(
  33. partitions[0],
  34. from.address,
  35. to.address,
  36. amount,
  37. ZeroHash,
  38. ZeroHash,
  39. {
  40. // gasPrice: 0,
  41. gasLimit: 2100000,
  42. nonce: nonce,
  43. type: 2,
  44. chainId: 1337
  45. }
  46. );
  47. const signed = await signer.signTransaction(tx);
  48. return signed;
  49. }
  50. async function getOperatorGrantData(symbol:string,signer:Wallet,tobeOperator: Wallet): Promise<any> {
  51. const proxy = getDeploymentAddresses(symbol).address;
  52. console.log(`토큰 주소 : ${proxy}`);
  53. let nonce = await getNonce(signer.address);
  54. const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;
  55. const tx = await token.grantRole.populateTransaction(
  56. id('OPERATOR_ROLE'),tobeOperator,
  57. {
  58. gasLimit: 2100000,
  59. nonce: nonce,
  60. type: 2,
  61. chainId: 1337
  62. }
  63. );
  64. const signed = await signer.signTransaction(tx);
  65. return signed;
  66. }
  67. const calc = new Calulator();
  68. const rpcUrl = process.env.RPCURL;
  69. const provider = new JsonRpcProvider(rpcUrl);
  70. setProvider(provider);
  71. const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
  72. const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
  73. // const signer = new Wallet('0x55d1000aa2057a878b5f7902158615f889cb1e9b811f7e1e9c0b4518399ba84a',provider);
  74. const signer = issuer;
  75. const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
  76. const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
  77. async function main() {
  78. // const tx = await getTransferData('test001',holder2, holder1,1);
  79. // console.log(tx);
  80. const tx = await getOperatorGrantData('test001',signer,holder2);
  81. console.log(tx);
  82. }
  83. main();