當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript web3.toWei函數代碼示例

本文整理匯總了TypeScript中web3.toWei函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript toWei函數的具體用法?TypeScript toWei怎麽用?TypeScript toWei使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了toWei函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: beforeEach

 beforeEach(async () => {
   await token.setPrice(
     secondProduct.id,
     web3.toWei(new BigNumber(1), 'ether'),
     {
       from: creator
     }
   );
   secondProduct.price = web3.toWei(new BigNumber(1), 'ether').toNumber();
 });
開發者ID:JalelTounsi,項目名稱:dotta-license,代碼行數:10,代碼來源:AffiliateProgram.test.ts

示例2: describe

    describe('when calculating cuts for an affiliate', async () => {
      const priceTests = [
        {
          price: web3.toWei(1, 'ether'),
          rate: 1000,
          actual: web3.toWei(0.1, 'ether')
        },
        {
          price: web3.toWei(0.5, 'ether'),
          rate: 2500,
          actual: web3.toWei(0.125, 'ether')
        },
        {
          price: 1000,
          rate: 2,
          actual: 0
        },
        {
          price: 1234,
          rate: 123,
          actual: 15
        },
        {
          price: 1234,
          rate: 129,
          actual: 15
        }
      ];

      priceTests.forEach(test => {
        it(`should calculate the correct cut for price ${
          test.price
        } at rate ${test.rate / 100}%`, async () => {
          await affiliate.whitelist(affiliate1, test.rate, { from: creator });
          const givenCut = await affiliate.cutFor(
            affiliate1,
            0,
            0,
            test.price,
            {
              from: creator
            }
          );
          givenCut.should.be.bignumber.equal(new BigNumber(test.actual));
        });
      });
    });
開發者ID:JalelTounsi,項目名稱:dotta-license,代碼行數:47,代碼來源:AffiliateProgram.test.ts

示例3: before

  before(async () => {
    const contracts = JSON.parse((await readFileAsync(path.join(__dirname, 'contracts.json'))).toString());
    accounts = await promisify<string[]>(web3.eth, 'getAccounts')();
    sender = accounts[0];
    receiver = accounts[1];

    // deploy token contract with last account
    const Token = web3.eth.contract(contracts[TOKEN]['abi']);
    let token = await new Promise<Web3.ContractInstance>((resolve, reject) =>
      Token.new(
        TOKEN_SUPLY,
        TOKEN,
        'TKN',
        DECIMALS,
        {
          gas: 5e6,
          from: accounts[accounts.length-1],
          data: contracts[TOKEN]['bytecode'],
        },
        (err, contract) => {
          if (err)
            return reject(err);
          else if (contract.address)
            return resolve(contract);
        }
      )
    );

    // mint 50 tkns to sender and receiver
    for (let acc of [sender, receiver]) {
      promisify<string>(token.mint, 'sendTransaction')({
        from: acc,
        value: web3.toWei(0.1, 'ether'),
      });
    }

    // deploy channel manager contract with last account and token
    const ChannelManager = web3.eth.contract(contracts[CHANNEL_MANAGER]['abi']);
    let channel_manager = await new Promise<Web3.ContractInstance>((resolve, reject) =>
      ChannelManager.new(
        token.address,
        CHALLENGE_PERIOD,
        [],
        {
          gas: 5e6,
          from: accounts[accounts.length-1],
          data: contracts[CHANNEL_MANAGER]['bytecode'],
        },
        (err, contract) => {
          if (err)
            return reject(err);
          else if (contract.address)
            return resolve(contract);
        }
      )
    );

    expect(token.address).to.match(addr_re);
    expect(channel_manager.address).to.match(addr_re);

    // init uraiden
    uraiden = new MicroRaiden(
      web3,
      channel_manager.address,
      channel_manager.abi,
      token.address,
      token.abi,
    );
  });
開發者ID:AlphaX-IBS,項目名稱:microraiden,代碼行數:69,代碼來源:microraiden.ts

示例4: toWei

 public toWei(ethAmount: BigNumber.BigNumber): BigNumber.BigNumber {
     const balanceWei = this.web3.toWei(ethAmount, 'ether');
     return balanceWei;
 }
開發者ID:linki,項目名稱:0x.js,代碼行數:4,代碼來源:web3_wrapper.ts


注:本文中的web3.toWei函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。