How to use iotex-antenna - 10 common examples

To help you get started, we’ve selected a few iotex-antenna examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iotexproject / iotex-explorer / src / shared / wallet / contract / interact.tsx View on Github external
abi,
          contractAddress,
          method: selectedFunction,
          gasPrice,
          gasLimit
        })},`,
        ...args,
        ")"
      );

      try {
        // TODO(tian): what if multiple values returned?
        const result = await antenna.iotx.readContractByMethod(
          {
            from: fromAddress,
            amount: toRau(amount, "Iotx"),
            abi,
            contractAddress,
            method: selectedFunction,
            gasPrice,
            gasLimit
          },
          ...args
        );
        window.console.log(
          `readContractByMethod result=${JSON.stringify(result)}`
        );
        this.setState({ outputValues: [].concat(result) });
      } catch (e) {
        notification.error({
          message: e.message
        });
github iotexproject / iotex-explorer / src / erc20 / erc20.ts View on Github external
method: string,
    account: Account,
    amount: string,
    // tslint:disable-next-line
    ...args: Array
  ): Promise {
    const execution = this.contract.pureEncodeMethod(amount, method, ...args);
    const executionMethod = new ExecutionMethod(
      getAntenna().iotx,
      account,
      execution
    );
    const { gasPrice } = await getAntenna().iotx.suggestGasPrice({});
    const envelop = await executionMethod.baseEnvelop("100000", `${gasPrice}`);
    envelop.execution = execution;
    const selp = SealedEnvelop.sign(
      account.privateKey,
      account.publicKey,
      envelop
    );

    let gasLimit = "400000";
    try {
      const { gas } = await getAntenna().iotx.estimateGasForAction({
        action: selp.action()
      });
      gasLimit = new BigNumber(gas)
        .multipliedBy(GAS_LIMIT_MULTIPLIED_BY)
        .toFixed(0);
    } catch (e) {
      window.console.log("estimateGasForAction failed!");
    }
github iotexproject / iotex-explorer / src / shared / wallet / decode-contract-data.ts View on Github external
return `${i.name}`;
        }),
        inputsTypes: args.map(i => {
          return `${i.type}`;
        })
      };

      const params = ethereumjs.rawDecode(
        methodDef.inputsTypes,
        Buffer.from(data.substring(8), "hex")
      );
      const values = {};

      for (let i = 0; i < methodDef.inputsTypes.length; i++) {
        if (methodDef.inputsTypes[i] === "address") {
          params[i] = fromBytes(
            Buffer.from(params[i].toString(), "hex")
          ).string();
        }
        // @ts-ignore
        values[method.inputsNames[i]] = params[i];
      }

      return {
        method: methodDef.name,
        data: values
      };
    }
  }

  window.console.warn("can not found method");
  return { method: data, data: {} };
github iotexproject / iotex-explorer / src / shared / action / action-receipt.tsx View on Github external
const receipt =
            get(data || {}, "getReceiptByAction.receiptInfo.receipt") || {};

          // @ts-ignore
          if (receipt.__typename) {
            // @ts-ignore
            delete receipt.__typename;
          }

          const gasPrice = Number(get(action, "core.gasPrice"));
          const gasConsumed = Number(get(receipt, "gasConsumed"));

          const dataSource = buildKeyValueArray({
            ...receipt,
            actionFee: `${fromRau(`${gasConsumed * gasPrice}`, "IOTX")} IOTX`
          });

          return (
            
              
                {t("title.receipt")}
github iotexproject / iotex-explorer / src / shared / wallet / transfer / transfer.tsx View on Github external
const {
      recipient,
      amount,
      gasLimit,
      gasPrice,
      symbol,
      dataInHex
    } = form.getFieldsValue();
    const tokenSymbol = symbol === "iotx" ? "IOTX" : tokens[symbol].symbol;
    const dataSource: { [index: string]: string } = {
      address: address,
      toAddress: recipient,
      amount: `${new BigNumber(amount).toString()} ${tokenSymbol}`,
      limit: gasLimit,
      price: `${toRau(gasPrice, "Qev")} (${gasPrice} Qev)`
    };

    if (tokenSymbol.match(/iotx/i)) {
      dataSource.dataInHex = `${dataInHex || " "}`; // Fix undefined and always display Data field in modal if it is needed.
    }

    return (
      
    );
  };
github iotexproject / iotex-explorer / src / erc20 / erc20.ts View on Github external
public async estimateExecutionGas(
    method: string,
    account: Account,
    amount: string,
    // tslint:disable-next-line
    ...args: Array
  ): Promise {
    const execution = this.contract.pureEncodeMethod(amount, method, ...args);
    const executionMethod = new ExecutionMethod(
      getAntenna().iotx,
      account,
      execution
    );
    const { gasPrice } = await getAntenna().iotx.suggestGasPrice({});
    const envelop = await executionMethod.baseEnvelop("100000", `${gasPrice}`);
    envelop.execution = execution;
    const selp = SealedEnvelop.sign(
      account.privateKey,
      account.publicKey,
      envelop
    );

    let gasLimit = "400000";
    try {
      const { gas } = await getAntenna().iotx.estimateGasForAction({
github iotexproject / iotex-explorer / src / shared / wallet / unlock-by-ledger.tsx View on Github external
.then(async transport => {
              transport.setDebugMode(true);
              const app = new IoTeXApp(transport);
              const result = await app.publicKey([44, 304, 0, 0, 0]);
              await transport.close();
              const address = publicKeyToAddress(
                result.publicKey.toString("hex")
              );
              const account = { address: address };
              getAntenna();
              window.signerPlugin.address = address;
              window.signerPlugin.publicKey = result.publicKey;
              // @ts-ignore
              dispatch(setAccount(account));
            })
            .catch((e: Error) => {
github iotexproject / iotex-explorer / src / shared / pages / action-detail-page.tsx View on Github external
const parseActionDetails = (data: IActionsDetails) => {
  // destruct receipt info
  const { blkHeight, gasConsumed, status, logs, contractAddress }: Dict =
    get(data, "receipt.receiptInfo.receipt") || {};

  // destruct action core info
  const { gasLimit, gasPrice, grantReward, execution, nonce, transfer }: Dict =
    get(data, "action.actionInfo.0.action.core") || {};

  const { timestamp, actHash }: Dict = get(data, "action.actionInfo.0") || {};

  const { senderPubKey }: Dict = get(data, "action.actionInfo.0.action") || {};

  const from = (senderPubKey && publicKeyToAddress(senderPubKey)) || undefined;

  return {
    status,
    blkHeight,
    timestamp,
    from,
    ...(execution ? { to: { execution, contractAddress } } : {}),
    ...(transfer ? { to: { transfer } } : {}),
    ...(grantReward ? { actionType: t("render.value.grantReward") } : {}),
    ...(execution ? { evmTransfer: actHash, value: execution.amount } : {}),
    ...(transfer ? { value: transfer.amount } : {}),
    fee: `${fromRau(`${gasConsumed * Number(gasPrice)}`, "Iotx")} IOTX`,
    gasLimit: Number(gasLimit).toLocaleString(),
    gasPrice: `${Number(gasPrice).toLocaleString()} (${fromRau(
      gasPrice,
      "Qev"
github iotexproject / iotex-explorer / src / shared / wallet / get-antenna.ts View on Github external
export function getAntenna(): Antenna {
  const injectedWindow: Window & { antenna?: Antenna } = window;
  if (injectedWindow.antenna) {
    return injectedWindow.antenna;
  }
  const url = isElectron()
    ? "https://iotexscan.io/iotex-core-proxy"
    : "/iotex-core-proxy";
  // @ts-ignore
  injectedWindow.signerPlugin = new LedgerSigner();
  injectedWindow.antenna = new Antenna(url, {
    // @ts-ignore
    signer: injectedWindow.signerPlugin
  });
  return injectedWindow.antenna;
}
github iotexproject / iotex-explorer / src / shared / wallet / add-custom-rpc-form-modal.tsx View on Github external
import Input from "antd/lib/input";
import Modal from "antd/lib/modal";
import notification from "antd/lib/notification";

import { WrappedFormUtils } from "antd/lib/form/Form";
import Antenna from "iotex-antenna";
// @ts-ignore
import { t } from "onefx/lib/iso-i18n";
import React from "react";
import { formItemLayout } from "../common/form-item-layout";
import { rulesMap } from "../common/rules";
import { colors } from "../common/styles/style-color";
import { FormItemLabel } from "./contract/cards";
import { IRPCProvider } from "./wallet-reducer";

const antennaTest = new Antenna("");
export interface IAddCustomRPCFormModalProps {
  onOK(network: IRPCProvider): void;
  onCancel(): void;
  visible?: boolean;
  form: WrappedFormUtils;
}
class AddCustomRPCFormModalCom extends React.PureComponent<
  IAddCustomRPCFormModalProps
> {
  public state: { confirming: boolean } = {
    confirming: false
  };
  public handleOk = async () => {
    const { form, onOK } = this.props;
    if (!onOK) {
      return;