當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ethers.utils類代碼示例

本文整理匯總了TypeScript中ethers.utils的典型用法代碼示例。如果您正苦於以下問題:TypeScript utils類的具體用法?TypeScript utils怎麽用?TypeScript utils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了utils類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: deposit

  public async deposit(
    address: Address,
    amount: ethers.utils.BigNumber,
    threshold: ethers.utils.BigNumber
  ) {
    const stateChannelInfo = await this.queryStateChannel();
    const isPeerA =
      stateChannelInfo.data.stateChannel.freeBalance.alice === this.fromAddress;

    const signingKeys = [this.toAddress, this.fromAddress];
    const appInstance = new ETHBalanceRefundApp(address, signingKeys);
    const deposits = {
      [this.fromAddress]: ethers.utils.bigNumberify("0"),
      [this.toAddress]: ethers.utils.bigNumberify("0")
    };
    const state = [this.fromAddress, this.multisigAddress, threshold];

    const balanceRefund = await this.install(
      "ETHBalanceRefundApp",
      appInstance,
      deposits,
      state
    );
    await this.depositToMultisig(amount);
    await balanceRefund.uninstall({
      peerABalance: isPeerA ? amount : ethers.utils.bigNumberify(0),
      peerBBalance: isPeerA ? ethers.utils.bigNumberify(0) : amount
    });
  }
開發者ID:cylof22,項目名稱:monorepo,代碼行數:29,代碼來源:channel.ts

示例2:

const signaturesAndDigests = ["sig1", "sig3", "sig2"].map(message => {
  const bytes = ethers.utils.toUtf8Bytes(message);
  const digest = ethers.utils.keccak256(bytes);
  const signature = signingKey.signDigest(digest);

  return {
    digest,
    signature
  };
});
開發者ID:cylof22,項目名稱:monorepo,代碼行數:10,代碼來源:signature.spec.ts

示例3: terms

 public static terms(): Terms {
   // FIXME: Change implementation of free balance on contracts layer
   // https://github.com/counterfactual/monorepo/issues/118
   return new Terms(
     0, // 0 means ETH
     ethers.utils.parseEther("0.001"), // FIXME: un-hardcode (https://github.com/counterfactual/monorepo/issues/117)
     ethers.constants.AddressZero
   );
 }
開發者ID:cylof22,項目名稱:monorepo,代碼行數:9,代碼來源:free-balance.ts

示例4: constructor

  constructor(appAddress: string, signingKeys: string[]) {
    const timeout = 100;
    const terms = new Terms(
      0,
      ethers.utils.bigNumberify("0"),
      ethers.constants.AddressZero
    );
    const abiEncodings = AppInstance.generateAbiEncodings(
      ETHBalanceRefundAppContract.abi
    );

    const appDefinition: AppDefinition = {
      address: appAddress,
      appStateEncoding: abiEncodings.appStateEncoding,
      appActionEncoding: abiEncodings.appActionEncoding
    };

    super(signingKeys, appDefinition, terms, timeout);
  }
開發者ID:cylof22,項目名稱:monorepo,代碼行數:19,代碼來源:eth-balance-refund-app.ts

示例5: generateAbiEncodings

  // TODO: temp hack necessary until ethers support https://github.com/ethers-io/ethers.js/issues/325
  static generateAbiEncodings(
    abi: string | (string | ethers.utils.ParamType)[]
  ): AbiEncodings {
    const iface = new ethers.utils.Interface(abi);
    const appFunctionNames = Object.keys(iface.functions).filter(fn => {
      return fn.indexOf("(") === -1;
    });
    const appActions = appFunctionNames.map(fn => {
      const inputs = iface.functions[fn].inputs;
      const tuples = inputs.map(input => {
        return ethers.utils.formatParamType(input);
      });

      return `${fn}(${tuples.join(",")})`;
    });

    return {
      appStateEncoding: ethers.utils.formatParamType(
        iface.functions.resolve.inputs[0]
      ),
      appActionEncoding: JSON.stringify([appActions.join(",")])
    };
  }
開發者ID:cylof22,項目名稱:monorepo,代碼行數:24,代碼來源:app-instance.ts

示例6: constructor

 constructor(
   readonly address: Address,
   balance: number | ethers.utils.BigNumber
 ) {
   this.balance = ethers.utils.bigNumberify(balance.toString());
 }
開發者ID:cylof22,項目名稱:monorepo,代碼行數:6,代碼來源:peer-balance.ts

示例7:

const deserializeBigNumber = data => ethers.utils.bigNumberify(data._hex);
開發者ID:cylof22,項目名稱:monorepo,代碼行數:1,代碼來源:serializer.ts

示例8:

 const tuples = inputs.map(input => {
   return ethers.utils.formatParamType(input);
 });
開發者ID:cylof22,項目名稱:monorepo,代碼行數:3,代碼來源:app-instance.ts

示例9: encodePacked

export function encodePacked(types: string[], values: any[]) {
  return ethers.utils.solidityPack(types, values);
}
開發者ID:cylof22,項目名稱:monorepo,代碼行數:3,代碼來源:abi.ts

示例10: signaturesToBytes

 sigs.sort((sigA, sigB) => {
   const addrA = ethers.utils.recoverAddress(digest, signaturesToBytes(sigA));
   const addrB = ethers.utils.recoverAddress(digest, signaturesToBytes(sigB));
   return new ethers.utils.BigNumber(addrA).lt(addrB) ? -1 : 1;
 });
開發者ID:cylof22,項目名稱:monorepo,代碼行數:5,代碼來源:signature.ts


注:本文中的ethers.utils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。