本文整理汇总了TypeScript中@0xproject/web3-wrapper.Web3Wrapper.getAvailableAddressesAsync方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Web3Wrapper.getAvailableAddressesAsync方法的具体用法?TypeScript Web3Wrapper.getAvailableAddressesAsync怎么用?TypeScript Web3Wrapper.getAvailableAddressesAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@0xproject/web3-wrapper.Web3Wrapper
的用法示例。
在下文中一共展示了Web3Wrapper.getAvailableAddressesAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateProviderToInjectedAsync
public async updateProviderToInjectedAsync() {
utils.assert(!_.isUndefined(this._zeroEx), 'ZeroEx must be instantiated.');
if (_.isUndefined(this._cachedProvider)) {
return; // Going from injected to injected, so we noop
}
this._blockchainWatcher.destroy();
const provider = this._cachedProvider;
this.networkId = this._cachedProviderNetworkId;
const shouldPollUserAddress = true;
this._web3Wrapper = new Web3Wrapper(provider);
this._blockchainWatcher = new BlockchainWatcher(
this._dispatcher,
this._web3Wrapper,
this.networkId,
shouldPollUserAddress,
);
const userAddresses = await this._web3Wrapper.getAvailableAddressesAsync();
this._userAddressIfExists = userAddresses[0];
this._zeroEx.setProvider(provider, this.networkId);
await this.fetchTokenInformationAsync();
this._blockchainWatcher.startEmittingNetworkConnectionAndUserBalanceState();
this._dispatcher.updateProviderType(ProviderType.Injected);
delete this._ledgerSubprovider;
delete this._cachedProvider;
}
示例2: _getFromAddressAsync
/**
* Gets the address to use for sending a transaction.
* @return The default from address. If not specified, returns the first address accessible by web3.
*/
private async _getFromAddressAsync(): Promise<string> {
let from: string;
if (_.isUndefined(this._defaults.from)) {
const accounts = await this.web3Wrapper.getAvailableAddressesAsync();
from = accounts[0];
} else {
from = this._defaults.from;
}
return from;
}
示例3: _onPageLoadInitFireAndForgetAsync
private async _onPageLoadInitFireAndForgetAsync() {
await utils.onPageLoadAsync(); // wait for page to load
// Hack: We need to know the networkId the injectedWeb3 is connected to (if it is defined) in
// order to properly instantiate the web3Wrapper. Since we must use the async call, we cannot
// retrieve it from within the web3Wrapper constructor. This is and should remain the only
// call to a web3 instance outside of web3Wrapper in the entire dapp.
// In addition, if the user has an injectedWeb3 instance that is disconnected from a backing
// Ethereum node, this call will throw. We need to handle this case gracefully
const injectedWeb3 = (window as any).web3;
let networkIdIfExists: number;
if (!_.isUndefined(injectedWeb3)) {
try {
networkIdIfExists = _.parseInt(await promisify<string>(injectedWeb3.version.getNetwork)());
} catch (err) {
// Ignore error and proceed with networkId undefined
}
}
const provider = await Blockchain._getProviderAsync(injectedWeb3, networkIdIfExists);
this.networkId = !_.isUndefined(networkIdIfExists)
? networkIdIfExists
: configs.IS_MAINNET_ENABLED ? constants.NETWORK_ID_MAINNET : constants.NETWORK_ID_KOVAN;
this._dispatcher.updateNetworkId(this.networkId);
const zeroExConfigs = {
networkId: this.networkId,
};
this._zeroEx = new ZeroEx(provider, zeroExConfigs);
this._updateProviderName(injectedWeb3);
const shouldPollUserAddress = true;
this._web3Wrapper = new Web3Wrapper(provider);
this._blockchainWatcher = new BlockchainWatcher(
this._dispatcher,
this._web3Wrapper,
this.networkId,
shouldPollUserAddress,
);
const userAddresses = await this._web3Wrapper.getAvailableAddressesAsync();
this._userAddressIfExists = userAddresses[0];
this._dispatcher.updateUserAddress(this._userAddressIfExists);
await this.fetchTokenInformationAsync();
this._blockchainWatcher.startEmittingNetworkConnectionAndUserBalanceState();
await this._rehydrateStoreWithContractEvents();
}
示例4: async
async () => {
// Check for network state changes
let currentNetworkId;
try {
currentNetworkId = await this._web3Wrapper.getNetworkIdAsync();
} catch (err) {
// Noop
}
if (currentNetworkId !== this._prevNetworkId) {
this._prevNetworkId = currentNetworkId;
this._dispatcher.updateNetworkId(currentNetworkId);
}
// Check for node version changes
const currentNodeVersion = await this._web3Wrapper.getNodeVersionAsync();
if (currentNodeVersion !== prevNodeVersion) {
prevNodeVersion = currentNodeVersion;
this._dispatcher.updateNodeVersion(currentNodeVersion);
}
if (this._shouldPollUserAddress) {
const addresses = await this._web3Wrapper.getAvailableAddressesAsync();
const userAddressIfExists = addresses[0];
// Update makerAddress on network change
if (this._prevUserAddressIfExists !== userAddressIfExists) {
this._prevUserAddressIfExists = userAddressIfExists;
this._dispatcher.updateUserAddress(userAddressIfExists);
}
// Check for user ether balance changes
if (!_.isUndefined(userAddressIfExists)) {
await this._updateUserWeiBalanceAsync(userAddressIfExists);
}
} else {
// This logic is primarily for the Ledger, since we don't regularly poll for the address
// we simply update the balance for the last fetched address.
if (!_.isUndefined(this._prevUserAddressIfExists)) {
await this._updateUserWeiBalanceAsync(this._prevUserAddressIfExists);
}
}
},
示例5: async
export const runMigrationsAsync = async (deployer: Deployer) => {
const web3Wrapper: Web3Wrapper = deployer.web3Wrapper;
const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync();
const tokenTransferProxy = await deployer.deployAndSaveAsync(ContractName.TokenTransferProxy);
const zrxToken = await deployer.deployAndSaveAsync(ContractName.ZRXToken);
const etherToken = await deployer.deployAndSaveAsync(ContractName.EtherToken);
const tokenReg = await deployer.deployAndSaveAsync(ContractName.TokenRegistry);
const exchangeArgs = [zrxToken.address, tokenTransferProxy.address];
const owners = [accounts[0], accounts[1]];
const confirmationsRequired = new BigNumber(2);
const secondsRequired = new BigNumber(0);
const multiSigArgs = [owners, confirmationsRequired, secondsRequired, tokenTransferProxy.address];
const exchange = await deployer.deployAndSaveAsync(ContractName.Exchange, exchangeArgs);
const multiSig = await deployer.deployAndSaveAsync(
ContractName.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,
multiSigArgs,
);
const owner = accounts[0];
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner });
await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: owner });
const addTokenGasEstimate = await tokenReg.addToken.estimateGasAsync(
zrxToken.address,
tokenInfo[0].name,
tokenInfo[0].symbol,
tokenInfo[0].decimals,
tokenInfo[0].ipfsHash,
tokenInfo[0].swarmHash,
{ from: owner },
);
await tokenReg.addToken.sendTransactionAsync(
zrxToken.address,
'0x Protocol Token',
'ZRX',
18,
constants.NULL_BYTES,
constants.NULL_BYTES,
{
from: owner,
gas: addTokenGasEstimate,
},
);
await tokenReg.addToken.sendTransactionAsync(
etherToken.address,
'Ether Token',
'WETH',
18,
constants.NULL_BYTES,
constants.NULL_BYTES,
{
from: owner,
gas: addTokenGasEstimate,
},
);
for (const token of tokenInfo) {
const totalSupply = new BigNumber(0);
const args = [token.name, token.symbol, token.decimals, totalSupply];
const dummyToken = await deployer.deployAsync(ContractName.DummyToken, args);
await tokenReg.addToken.sendTransactionAsync(
dummyToken.address,
token.name,
token.symbol,
token.decimals,
token.ipfsHash,
token.swarmHash,
{
from: owner,
gas: addTokenGasEstimate,
},
);
}
};