ethers#Wallet JavaScript Examples
The following examples show how to use
ethers#Wallet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: demo-accounts.js From MetaSwap with MIT License | 5 votes |
relayer = Wallet.fromMnemonic(mnemonic, "m/44'/60'/0'/0/3")
Example #2
Source File: demo-accounts.js From MetaSwap with MIT License | 5 votes |
makerAdmin = Wallet.fromMnemonic(mnemonic, "m/44'/60'/0'/0/0")
Example #3
Source File: demo-accounts.js From MetaSwap with MIT License | 5 votes |
takerAdmin = Wallet.fromMnemonic(mnemonic, "m/44'/60'/0'/0/1")
Example #4
Source File: demo-accounts.js From MetaSwap with MIT License | 5 votes |
makerSigner = Wallet.fromMnemonic(mnemonic, "m/44'/60'/0'/1/0")
Example #5
Source File: demo-accounts.js From MetaSwap with MIT License | 5 votes |
takerSigner = Wallet.fromMnemonic(mnemonic, "m/44'/60'/0'/1/1")
Example #6
Source File: misc.js From MetaSwap with MIT License | 5 votes |
owner = new Wallet(ganacheAccount)
Example #7
Source File: misc.js From MetaSwap with MIT License | 5 votes |
alice = new Wallet('0x0000000000000000000000000000000000000000000000000000000000000002')
Example #8
Source File: misc.js From MetaSwap with MIT License | 5 votes |
bob = new Wallet('0x0000000000000000000000000000000000000000000000000000000000000001')
Example #9
Source File: claim.js From ethernal with MIT License | 4 votes |
store = derived(
wallet,
async ($wallet, set) => {
const _set = obj => {
$claim = { ...$claim, ...obj };
log.info('CLAIM', JSON.stringify($claim, null, ' '));
set($claim);
};
const gasPrice = BigNumber.from('1000000000'); // await provider.getGasPrice();
const gasLimit = BigNumber.from(21000);
const gasFee = gasLimit.mul(gasPrice);
const extraValue = BigNumber.from('100000000000000');
const minimum = gasFee.add(extraValue);
const maximum = BigNumber.from('4000000000000000000'); // @TODO: config)
if (claimKey && typeof $claim.rawBalance === 'undefined') {
try {
claimWallet = new Wallet(claimKey);
const provider = wallet.getFallbackProvider();
if (provider) {
(async () => {
let claimBalance = await wallet.getFallbackProvider().getBalance(claimWallet.address);
if (claimBalance.lt(minimum)) {
claimBalance = BigNumber.from(0);
}
if (claimBalance.gt(maximum)) {
claimBalance = maximum;
}
// eslint-disable-next-line no-console
console.log({
address: claimWallet.address,
status: 'WaitingWallet',
rawBalance: claimBalance,
balance: utils.formatUnits(claimBalance, 18),
});
_set({
status: 'WaitingWallet',
rawBalance: claimBalance,
balance: utils.formatUnits(claimBalance, 18),
});
})();
}
} catch (e) {
const claimBalance = BigNumber.from(0);
_set({
status: 'WaitingWallet',
rawBalance: claimBalance,
balance: utils.formatUnits(claimBalance, 18),
});
}
}
async function claim() {
_set({ status: 'Loading' });
const provider = wallet.getProvider();
let claimingTxHash;
const localStorageKeyForClaimTxHash = `${$wallet.address}_${$wallet.chainId}_claimTxHash`;
try {
claimingTxHash = localStorage.getItem(localStorageKeyForClaimTxHash);
} catch (err) {
//
}
if (claimingTxHash && claimingTxHash !== '') {
_set({ status: 'WaitingOldTx' });
const tx = await provider.getTransaction(claimingTxHash);
if (tx) {
const receipt = await tx.wait();
if (tx.blockNumber) {
if (receipt.status === 1) {
_set({ status: 'Claimed' });
clearClaimKey();
return;
}
_set({ status: 'Failed' });
} else {
const txReceipt = await tx.wait();
if (txReceipt.status === 1) {
_set({ status: 'Claimed' });
clearClaimKey();
return;
}
_set({ status: 'Failed' });
}
} else {
log.trace(`cannot find tx ${claimingTxHash}`);
}
}
const claimBalance = await provider.getBalance(claimWallet.address);
log.trace({ claimBalance });
const claimValue = BigNumber.from('5000000000000000000'); // @TODO: from Config 5 DAI
if (claimBalance.gte(minimum)) {
const signer = claimWallet.connect(provider);
let value = claimBalance.sub(gasFee);
const maxValue = BigNumber.from(claimValue);
if (value.gt(maxValue)) {
value = maxValue;
}
_set({ status: 'Claiming' });
const tx = await signer.sendTransaction({
to: $wallet.address,
value,
gasLimit,
gasPrice,
});
localStorage.setItem(localStorageKeyForClaimTxHash, tx.hash);
_set({ status: 'WaitingTx' });
const receipt = await tx.wait();
if (receipt.status === 1) {
_set({ status: 'Claimed' });
clearClaimKey();
return;
}
_set({ status: 'Failed' });
} else {
_set({ status: 'Gone' });
}
clearClaimKey();
}
store.claim = claim;
store.acknowledge = () => {
_set({ status: 'None' });
};
},
$claim,
)