How to use @zilliqa-js/core - 10 common examples

To help you get started, we’ve selected a few @zilliqa-js/core 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 Zilliqa / nucleus-wallet / src / redux / zil / sagas.ts View on Github external
version: VERSION,
        toAddr,
        amount: units.toQa(amount, units.Units.Zil),
        gasPrice: new BN(minGasPriceInQa),
        gasLimit: Long.fromNumber(1),
        pubKey: publicKey,
        nonce
      },
      provider
    );

    const signedTx = yield wallet.sign(tx);
    const { txParams } = signedTx;

    // Send a transaction to the network
    const data = yield provider.send(RPCMethod.CreateTransaction, txParams);

    if (data.error !== undefined) {
      throw Error(data.error.message);
    }

    const sendTxId = data.result.TranID;

    yield put({
      type: consts.SEND_TX_SUCCEEDED,
      payload: { sendTxId }
    });
  } catch (error) {
    console.log(error);
    yield put({ type: consts.SEND_TX_FAILED });
  }
}
github Zilliqa / nucleus-wallet / functions / src / index.ts View on Github external
{
        version: VERSION,
        toAddr,
        amount,
        gasPrice,
        gasLimit,
        pubKey,
        nonce
      },
      provider
    );
    const signedTx = await wallet.sign(tx);
    const { txParams } = signedTx;

    // Send a transaction to the network
    const tsRes = await provider.send(RPCMethod.CreateTransaction, txParams);
    const { result } = tsRes;
    const txId = result && result.TranID;

    if (txId === undefined) {
      console.log('Response', tsRes);
      throw Error('No TxID!');
    }

    console.log(`TxID: ${txId}`);

    const now = Date.now();
    const userData = {
      claimed_at: now
    };
    await userRef.set(userData);
    console.log(`Claimed at: ${now}`);
github zilpay / zil-pay / extension / inpage / browser / zilPay.js View on Github external
reject('User denied access!');
          result.unsubscribe();
        }
        // Close stream by time.
        setTimeout(() => {
          result.unsubscribe();
          reject(new Error('waiting time may have problems ZilPay'));
        }, 15000);
      });
    });
  }

}


window.zilPay = new ZilPay(new HTTPProvider(PROVIDER));

if (typeof window.Zilliqa !== 'undefined') {
  console.error('window.Zilliqa already exists');
}

window.Zilliqa = Zilliqa;


export default function run() {
  // Create instance in page. //
  
  const type = MTypesSecure.PAY_OBJECT_INIT;
  const recipient = MTypesSecure.CONTENT;

  observableStream(
    MTypesSecure.INJECTED,
github Zilliqa / nucleus-wallet / src / contexts / zil-context / index.tsx View on Github external
public send = async ({ args }): Promise => {
    const { amount, toAddress } = args;
    const { wallet } = this.state;
    const tx = new Transaction(await this.getParams(toAddress, amount), provider);
    const signedTx = await wallet.sign(tx);
    const { txParams } = signedTx;
    // Send a transaction to the network
    const res = await provider.send(RPCMethod.CreateTransaction, txParams);
    if (res.error !== undefined) throw new Error(res.error.message);
    return res.result ? res.result.TranID : undefined;
  };
github zilpay / zil-pay / extension / controllers / services / blockchain / zilliqa.js View on Github external
async signedTxSend(payload) {
    const tx =  await this.provider.send( // Send to shard node.
      RPCMethod.CreateTransaction, payload
    );
    return tx;
  }
github zilpay / zil-pay / src / controllers / services / blockchain / zilliqa.js View on Github external
const zilTxData = this.transactions.new({
      nonce,
      gasPrice,
      amount,
      gasLimit,
      version,
      toAddr,
      pubKey,
      code,
      data
    });
    // Sign transaction by current account. //
    const { txParams } = await this.wallet.sign(zilTxData);

    return await this.provider.send( // Send to shard node.
      RPCMethod.CreateTransaction, txParams
    );
  }
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-account / src / transaction.ts View on Github external
private async getBlockNumber(): Promise {
    try {
      const res: RPCResponse = await this.provider.send(
        RPCMethod.GetLatestTxBlock,
      );
      if (res.error === undefined && res.result.header.BlockNum) {
        // if blockNumber is too high, we use BN to be safer
        return new BN(res.result.header.BlockNum);
      } else {
        throw new Error('Can not get latest BlockNumber');
      }
    } catch (error) {
      throw error;
    }
  }
github zilpay / zil-pay / extension / inpage / browser / zilPay.js View on Github external
result.unsubscribe();
        resolve(
          Object.assign(tx, resultTx.resolve)
        );
      }

      // Close stream by time.
      setTimeout(() => {
        result.unsubscribe();
        reject(new Error('waiting time may have problems ZilPay'));
      }, 9000);
    });
  });
}

HTTPProvider.prototype.send = (method, params) => {
  const type = MTypesZilPay.PROXY_MEHTOD;
  const recipient = MTypesSecure.CONTENT;
  const uuid = uuidv4();
  
  new SecureMessage({
    type, payload: { params, method, uuid }
  }).send(stream, recipient);

  return new Promise((resolve, reject) => {
    const proxy = subjectStream.subscribe(result => {

      if (!result.uuid || result.uuid !== uuid) {
        return null;
      } else if (result.error) {
        reject(result.error);
      } else {
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-account / src / transaction.ts View on Github external
this.toAddr = normaliseAddress(params.toAddr);
    this.nonce = params.nonce;
    this.pubKey = params.pubKey;
    this.amount = params.amount;
    this.code = params.code || '';
    this.data = params.data || '';
    this.signature = params.signature;
    this.gasPrice = params.gasPrice;
    this.gasLimit = params.gasLimit;
    this.receipt = params.receipt;
    // public members
    this.provider = provider;
    this.status = status;
    this.toDS = toDS;
    this.blockConfirmation = 0;
    this.eventEmitter = new EventEmitter();
  }
github Zilliqa / nucleus-wallet / functions / src / index.ts View on Github external
const RECAPTCHA_SECRET = functions.config().faucet.recaptcha_secret;
const PRIVATE_KEY = functions.config().faucet.private_key;
const PUBLIC_KEY = getPubKeyFromPrivateKey(PRIVATE_KEY);
const ADDRESS = getAddressFromPrivateKey(PRIVATE_KEY);

const CHAIN_ID: number =
  process.env.REACT_APP_CHAIN_ID !== undefined ? parseInt(process.env.REACT_APP_CHAIN_ID, 10) : 0;
const MSG_VERSION: number =
  process.env.REACT_APP_MSG_VERSION !== undefined
    ? parseInt(process.env.REACT_APP_MSG_VERSION, 10)
    : 0;
const VERSION = bytes.pack(CHAIN_ID, MSG_VERSION);
const NODE_URL: string = process.env.REACT_APP_NODE_URL || '';

const provider = new HTTPProvider(NODE_URL);
const zilliqa = new Zilliqa(NODE_URL, provider);

zilliqa.wallet.addByPrivateKey(PRIVATE_KEY);

app.post('/run', async (req, res) => {
  const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
  console.log(`IP address: ${ip}`);
  console.log(`${NODE_URL}, ${CHAIN_ID}, ${MSG_VERSION}`);

  const { token, address } = req.body;
  try {
    const verificationUrl =
      'https://www.google.com/recaptcha/api/siteverify?secret=' +
      RECAPTCHA_SECRET +
      '&response=' +
      token +