web3-core#Account TypeScript Examples
The following examples show how to use
web3-core#Account.
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: test-crowdloan.ts From moonbeam with GNU General Public License v3.0 | 5 votes |
describeDevMoonbeam("Crowdloan", (context) => {
let sudoAccount: KeyringPair;
let numberOfAccounts: number = 1000; // min 2
let largInput: [string, string, bigint][];
before("Setup genesis account for substrate", async () => {
numberOfAccounts = Number(
(await context.polkadotApi.consts.crowdloanRewards.maxInitContributors) as any
);
const keyring = new Keyring({ type: "ethereum" });
sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum");
});
it("should be able to register many accounts : " + numberOfAccounts, async function () {
// should create a bunch of test eth accounts
this.timeout(30000);
let web3 = new Web3();
// We need to make sure the rewards match the account funds. 3M GLMR/ number of accounts
let accounts = new Array(numberOfAccounts).fill(0).map((_) => web3.eth.accounts.create());
largInput = accounts.map((acc: Account, i: number) => {
return [
acc.address + "111111111111111111111111",
acc.address,
(3_000_000n * GLMR) / BigInt(numberOfAccounts),
];
});
expect(largInput.length).to.eq(numberOfAccounts);
expect(largInput[0][1] !== largInput[numberOfAccounts - 1][1]).to.eq(true);
// should be able to register many accounts
await context.polkadotApi.tx.sudo
.sudo(context.polkadotApi.tx.crowdloanRewards.initializeRewardVec(largInput))
.signAndSend(sudoAccount);
await context.createBlock();
let initBlock = (await context.polkadotApi.query.crowdloanRewards.initRelayBlock()) as any;
// Complete initialization
await context.polkadotApi.tx.sudo
.sudo(
context.polkadotApi.tx.crowdloanRewards.completeInitialization(
initBlock.toBigInt() + VESTING_PERIOD
)
)
.signAndSend(sudoAccount);
await context.createBlock();
const rewardPerContributor = (3_000_000n * GLMR) / BigInt(numberOfAccounts);
await Promise.all(
largInput.map(async (input) => {
expect((await getAccountPayable(context, input[1])).totalReward.toBigInt()).to.equal(
rewardPerContributor
);
})
);
});
});
Example #2
Source File: test-crowdloan.ts From moonbeam with GNU General Public License v3.0 | 5 votes |
describeDevMoonbeam("Crowdloan", (context) => {
let sudoAccount: KeyringPair;
let numberOfAccounts: number = 1000; // min 2
let largInput: [string, string, bigint][];
before("Setup genesis account for substrate", async () => {
// We shouldnt be able to register as many accounts unless we do it in batches
numberOfAccounts = Number(
(await context.polkadotApi.consts.crowdloanRewards.maxInitContributors) as any
);
const keyring = new Keyring({ type: "ethereum" });
sudoAccount = await keyring.addFromUri(ALITH_PRIV_KEY, null, "ethereum");
});
it("should be able to register many accounts - batch : " + numberOfAccounts, async function () {
// should create a bunch of test eth accounts
this.timeout(20000);
let web3 = new Web3();
let accounts = new Array(numberOfAccounts).fill(0).map((_, i) => web3.eth.accounts.create());
largInput = accounts.map((acc: Account, i: number) => {
return [
acc.address + "111111111111111111111111",
acc.address,
(3_000_000n * GLMR) / BigInt(numberOfAccounts),
];
});
expect(largInput.length).to.eq(numberOfAccounts);
expect(largInput[0][1] !== largInput[numberOfAccounts - 1][1]).to.eq(true);
// should be able to register many accounts
await context.polkadotApi.tx.utility
.batch([
await context.polkadotApi.tx.sudo.sudo(
context.polkadotApi.tx.crowdloanRewards.initializeRewardVec(
largInput.slice(0, Math.floor(numberOfAccounts / 3))
)
),
await context.polkadotApi.tx.sudo.sudo(
context.polkadotApi.tx.crowdloanRewards.initializeRewardVec(
largInput.slice(
Math.floor(numberOfAccounts / 3),
Math.floor((numberOfAccounts * 2) / 3)
)
)
),
await context.polkadotApi.tx.sudo.sudo(
context.polkadotApi.tx.crowdloanRewards.initializeRewardVec(
largInput.slice(Math.floor((numberOfAccounts * 2) / 3), numberOfAccounts)
)
),
])
.signAndSend(sudoAccount);
await context.createBlock();
let initBlock = (await context.polkadotApi.query.crowdloanRewards.initRelayBlock()) as any;
// Complete initialization
await context.polkadotApi.tx.sudo
.sudo(
context.polkadotApi.tx.crowdloanRewards.completeInitialization(
initBlock.toBigInt() + VESTING_PERIOD
)
)
.signAndSend(sudoAccount);
await context.createBlock();
await Promise.all(
largInput.map(async (input) => {
expect((await getAccountPayable(context, input[1])).totalReward.toBigInt()).to.equal(
(3_000_000n * GLMR) / BigInt(numberOfAccounts)
);
})
);
});
});
Example #3
Source File: init-web3.ts From moonbeam with GNU General Public License v3.0 | 5 votes |
gerald: Account & { storageKey: string }