How to use the @0xcert/ethereum-gateway.Gateway function in @0xcert/ethereum-gateway

To help you get started, we’ve selected a few @0xcert/ethereum-gateway 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 0xcert / framework / packages / 0xcert-client / src / core / controllers / orders-controller.ts View on Github external
public async createOrder(order: ActionsOrder, priority: Priority) {
    if (!this.context.authentication) {
      throw new Error('Client not connected. Please initialize your client first.');
    }
    const orderGateway = new Gateway(this.context.provider);

    // Set order's payer.
    if (!order.payerId && !order.wildcardSigner) {
      throw new Error('Payer must be specified if `wildcardSigner` tag is set to false.');
    }

    // Checks if payer id is order's signer.
    if (order.payerId) {
      const isPayerSigner = order.signersIds.find((s) => s.toLowerCase() === order.payerId.toLowerCase());
      if (!isPayerSigner) {
        throw new Error('Payer must be listed as order\'s signer.');
      }
    }

    const multiplier = new BigNumber(1000000000000000000);
    const orderActions: FrameworkActionsOrderAction[] = [];
github 0xcert / framework / packages / 0xcert-client / src / core / controllers / deployments-controller.ts View on Github external
public async createDeployment(deployData: AssetLedgerDeploymentData, priority: Priority) {
    if (!this.context.authentication) {
      throw new Error('Client not connected. Please initialize your client first.');
    }
    const deployGateway = new Gateway(this.context.provider);
    const date = Date.now();
    const multiplier = new BigNumber(1000000000000000000);
    const paymentAmount = this.context.payment.assetDeployCost;
    const value = new BigNumber(paymentAmount).multipliedBy(multiplier);
    const assetLedgerDeployOrder = {
      kind: OrderKind.ASSET_LEDGER_DEPLOY_ORDER,
      makerId: this.context.provider.accountId,
      seed: date,
      expiration: Date.now() + 172800000, // 2 days
      tokenTransferData: {
        ledgerId: this.context.payment.tokenAddress,
        receiverId: this.context.payment.receiverAddress,
        value: value.toFixed(0),
      },
      assetLedgerData: deployData,
    };
github 0xcert / framework / packages / 0xcert-client / src / core / controllers / orders-controller.ts View on Github external
throw new Error('There was a problem while fetching order data.');
    }

    if (!order) {
      throw new Error('Order doesn\'t. exists');
    }

    const claimOrder = {
      kind: order.wildcardSigner ? OrderKind.SIGNED_DYNAMIC_ACTIONS_ORDER : OrderKind.SIGNED_FIXED_ACTIONS_ORDER,
      seed: order.order.seed,
      signers: order.order.signers.map((s: Signer) => s.accountId),
      expiration: order.order.expiration,
      actions: order.order.actions,
    } as FrameworkActionsOrder;

    const orderGateway = new Gateway(this.context.provider);
    const claim = await orderGateway.sign(claimOrder);

    return clientFetch(`${this.context.apiUrl}/orders/${orderRef}/sign`, {
      method: 'PUT',
      body: JSON.stringify({
        claim,
      }),
      headers: {
        'Content-Type': 'application/json',
        'Authorization': this.context.authentication,
      },
    });
  }