本文整理汇总了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();
});
示例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));
});
});
});
示例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,
);
});
示例4: toWei
public toWei(ethAmount: BigNumber.BigNumber): BigNumber.BigNumber {
const balanceWei = this.web3.toWei(ethAmount, 'ether');
return balanceWei;
}