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

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 zilpay / zil-pay / packages / inpage / zil-pay.js View on Github external
constructor(subjectStream, stream) {
    if (!subjectStream || !stream) {
      throw new Error('subjectStream and stream is necessary params.')
    }

    // Create instance Proxy provider.
    this.provider = new HTTPProvider(subjectStream, stream)
    // Redefined Wallet to work with user interface.
    this.wallet = new Wallet(subjectStream, stream)
    
    this.blockchain = new Blockchain(this.provider, this.wallet)
    this.contracts = new Contracts(this.provider, this.wallet)
    this.transactions = new TransactionFactory(this.provider, this.wallet)

    this.utils = zilUtils
    this.crypto = {
      fromBech32Address,
      toBech32Address,
      isValidChecksumAddress,
      toChecksumAddress
    }
  }
}
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;
    }
github zilpay / zil-pay / extension / inpage / browser / zilPay.js View on Github external
constructor(node=PROVIDER, provider=new HTTPProvider(PROVIDER)) {
    this.provider = provider || new HTTPProvider(node);
    this.wallet = window.zilPay;
    this.blockchain = new Blockchain(this.provider, this.wallet);
    this.contracts = new Contracts(this.provider, this.wallet);
    this.transactions = new TransactionFactory(this.provider, this.wallet);
    this.utils = zilUtils;
    this.crypto = {
      decodeBase58, encodeBase58,
      fromBech32Address, toBech32Address,
      isValidChecksumAddress, toChecksumAddress
    }
  }
}
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa / src / index.ts View on Github external
constructor(node: string, websocket: string, provider?: Provider) {
    this.provider = provider || new HTTPProvider(node);
    this.wallet = new Wallet(this.provider);
    this.blockchain = new Blockchain(this.provider, this.wallet);
    this.network = new Network(this.provider, this.wallet);
    this.contracts = new Contracts(this.provider, this.wallet);
    this.transactions = new TransactionFactory(this.provider, this.wallet);
    this.newTxBlockSubscription = new NewTxBlockSubscription(websocket);
  }
}
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-contract / src / factory.ts View on Github external
constructor(provider: Provider, signer: Wallet) {
    this.provider = provider;
    this.provider.middleware.request.use(
      util.formatOutgoingTx,
      RPCMethod.CreateTransaction,
    );
    this.signer = signer;
  }