How to use the @zilliqa-js/account.Transaction function in @zilliqa-js/account

To help you get started, we’ve selected a few @zilliqa-js/account 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 / functions / src / index.ts View on Github external
const gasResponse = await zilliqa.blockchain.getMinimumGasPrice();
    const minGasPrice: string = gasResponse.result;
    console.log('Min gas price:', minGasPrice);

    const gasPrice = new BN(minGasPrice);
    const pubKey = PUBLIC_KEY;
    const toAddr = address;

    const response = await zilliqa.blockchain.getBalance(ADDRESS);
    const nonceResult = response.result || { nonce: 0 };
    const nonce: number = nonceResult.nonce + 1;
    console.log('Nonce:', nonce);

    const wallet = zilliqa.wallet;
    wallet.addByPrivateKey(PRIVATE_KEY);
    const tx = new Transaction(
      {
        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);
github Zilliqa / nucleus-wallet / src / redux / zil / sagas.ts View on Github external
const zilState = yield select(getZilState);
    const { zilliqa, provider, privateKey, address, publicKey } = zilState;

    const response = yield zilliqa.blockchain.getMinimumGasPrice();
    const minGasPriceInQa: string = response.result;

    const nonceResponse = yield zilliqa.blockchain.getBalance(address);
    const nonceData = nonceResponse.result.nonce || { nonce: 0 };
    const nonce: number = nonceData.nonce + 1;

    const toAddr = fromBech32Address(toAddress);
    const wallet = zilliqa.wallet;
    wallet.addByPrivateKey(privateKey);

    const tx = new Transaction(
      {
        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
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 Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-contract / src / contract.ts View on Github external
async deployWithoutConfirm(
    params: DeployParams,
    toDs: boolean = false,
  ): Promise<[Transaction, Contract]> {
    if (!this.code || !this.init) {
      throw new Error(
        'Cannot deploy without code or initialisation parameters.',
      );
    }
    const tx = new Transaction(
      {
        ...params,
        toAddr: NIL_ADDRESS,
        amount: new BN(0),
        code: this.code,
        data: JSON.stringify(this.init).replace(/\\"/g, '"'),
      },
      this.provider,
      TxStatus.Initialised,
      toDs,
    );

    try {
      this.address = await this.prepare(tx);
      this.status =
        this.address === undefined
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-contract / src / contract.ts View on Github external
async deploy(
    params: DeployParams,
    attempts: number = 33,
    interval: number = 1000,
    toDs: boolean = false,
  ): Promise<[Transaction, Contract]> {
    if (!this.code || !this.init) {
      throw new Error(
        'Cannot deploy without code or initialisation parameters.',
      );
    }

    try {
      const tx = await this.prepareTx(
        new Transaction(
          {
            ...params,
            toAddr: NIL_ADDRESS,
            amount: new BN(0),
            code: this.code,
            data: JSON.stringify(this.init).replace(/\\"/g, '"'),
          },
          this.provider,
          TxStatus.Initialised,
          toDs,
        ),
        attempts,
        interval,
        true,
      );
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-contract / src / contract.ts View on Github external
const data = {
      _tag: transition,
      params: args,
    };

    if (this.error) {
      return Promise.reject(this.error);
    }

    if (!this.address) {
      return Promise.reject('Contract has not been deployed!');
    }

    try {
      return await this.prepareTx(
        new Transaction(
          {
            ...params,
            toAddr: this.address,
            data: JSON.stringify(data),
          },
          this.provider,
          TxStatus.Initialised,
          toDs,
        ),
        attempts,
        interval,
        false,
      );
    } catch (err) {
      throw err;
    }