From b54ebec936fb80ae96f2c32e756328e366d36313 Mon Sep 17 00:00:00 2001 From: Marko Petrlic Date: Thu, 17 Oct 2024 15:01:22 +0200 Subject: [PATCH] Added new extrinsic docs. Updated existing extrisnic docs --- avail-js/docs/advanced_examples/multisig.ts | 2 +- avail-js/docs/extrinsics/README.md | 180 +++++++++--------- .../docs/extrinsics/balances_tranfer_all.ts | 9 +- .../balances_tranfer_all_no_wait.ts | 17 ++ .../balances_tranfer_allow_death.ts | 11 +- .../balances_tranfer_allow_death_no_wait.ts | 17 ++ .../extrinsics/balances_tranfer_keep_alive.ts | 11 +- .../balances_tranfer_keep_alive_no_wait.ts | 17 ++ .../extrinsics/da_create_application_key.ts | 9 +- .../da_create_application_key_no_wait.ts | 16 ++ .../docs/extrinsics/da_set_aplication_key.ts | 9 +- .../da_set_submit_data_fee_modifier.ts | 11 +- .../da_submit_block_length_proposal.ts | 9 +- avail-js/docs/extrinsics/da_submit_data.ts | 11 +- .../docs/extrinsics/da_submit_data_no_wait.ts | 17 ++ .../extrinsics/nomination_pools_bond_extra.ts | 10 +- .../docs/extrinsics/nomination_pools_chill.ts | 8 +- .../nomination_pools_claim_commission.ts | 8 +- .../nomination_pools_claim_payout.ts | 8 +- .../nomination_pools_claim_payout_other.ts | 8 +- .../extrinsics/nomination_pools_create.ts | 10 +- .../nomination_pools_create_with_pool_id.ts | 10 +- .../docs/extrinsics/nomination_pools_join.ts | 10 +- .../extrinsics/nomination_pools_nominate.ts | 8 +- .../nomination_pools_set_claim_permission.ts | 8 +- .../nomination_pools_set_commission.ts | 8 +- .../nomination_pools_set_metadata.ts | 8 +- .../extrinsics/nomination_pools_set_state.ts | 8 +- .../extrinsics/nomination_pools_unbond.ts | 10 +- .../nomination_pools_withdraw_unbonded.ts | 8 +- avail-js/docs/extrinsics/staking_bond.ts | 11 +- .../docs/extrinsics/staking_bond_extra.ts | 11 +- avail-js/docs/extrinsics/staking_chill.ts | 9 +- .../docs/extrinsics/staking_chill_other.ts | 9 +- avail-js/docs/extrinsics/staking_nominate.ts | 9 +- avail-js/docs/extrinsics/staking_unbond.ts | 10 +- avail-js/docs/extrinsics/staking_validate.ts | 9 +- avail-js/docs/storage/da_app_keys.ts | 2 +- avail-js/docs/storage/da_app_keys_iter.ts | 2 +- avail-js/docs/storage/da_next_app_id.ts | 2 +- avail-js/docs/storage/staking_active_era.ts | 2 +- avail-js/docs/storage/staking_bonded.ts | 2 +- avail-js/docs/storage/staking_bonded_iter.ts | 2 +- avail-js/docs/storage/system_account.ts | 2 +- avail-js/docs/storage/system_account_iter.ts | 2 +- avail-js/src/sdk/account.ts | 19 +- avail-js/src/sdk/index.ts | 6 + avail-js/src/sdk/transactions/index.ts | 2 +- 48 files changed, 337 insertions(+), 250 deletions(-) create mode 100644 avail-js/docs/extrinsics/balances_tranfer_all_no_wait.ts create mode 100644 avail-js/docs/extrinsics/balances_tranfer_allow_death_no_wait.ts create mode 100644 avail-js/docs/extrinsics/balances_tranfer_keep_alive_no_wait.ts create mode 100644 avail-js/docs/extrinsics/da_create_application_key_no_wait.ts create mode 100644 avail-js/docs/extrinsics/da_submit_data_no_wait.ts diff --git a/avail-js/docs/advanced_examples/multisig.ts b/avail-js/docs/advanced_examples/multisig.ts index 5af63525f..645607825 100644 --- a/avail-js/docs/advanced_examples/multisig.ts +++ b/avail-js/docs/advanced_examples/multisig.ts @@ -15,7 +15,7 @@ const main = async () => { await fundMultisigAccount(sdk, alice, multisigAddress) // Define what action will be taken by the multisig account - const amount = new BN(10).pow(new BN(18)) // one Avail + const amount = SDK.oneAvail() const call = sdk.api.tx.balances.transferKeepAlive(multisigAddress, amount) // Data needed for multisig approval and execution const callHash = call.method.hash.toString() diff --git a/avail-js/docs/extrinsics/README.md b/avail-js/docs/extrinsics/README.md index 4fd093d66..03ce1231a 100644 --- a/avail-js/docs/extrinsics/README.md +++ b/avail-js/docs/extrinsics/README.md @@ -37,12 +37,12 @@ const main = async () => { const key = "MyAwesomeKey" const result = await sdk.tx.dataAvailability.createApplicationKey(key, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -108,12 +108,12 @@ const main = async () => { const data = "My Awesome Data" const result = await sdk.tx.dataAvailability.submitData(data, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -182,12 +182,12 @@ const main = async () => { const cols = 128 const result = await sdk.tx.dataAvailability.submitBlockLengthProposal(rows, cols, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -243,12 +243,12 @@ const main = async () => { const newKey = "MyNewKeyAwesome2" const result = await sdk.tx.dataAvailability.setApplicationKey(oldKey, newKey, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -305,12 +305,12 @@ const main = async () => { } as sdkTransactions.DispatchFeeModifier const result = await sdk.tx.dataAvailability.setSubmitDataFeeModifier(modifier, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -385,12 +385,12 @@ const main = async () => { const amount = new BN(10).pow(new BN(18)) // one Avail const result = await sdk.tx.balances.transferKeepAlive(dest, amount, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -458,12 +458,12 @@ const main = async () => { const amount = new BN(10).pow(new BN(18)) // one Avail const result = await sdk.tx.balances.transferAllowDeath(dest, amount, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -531,12 +531,12 @@ const main = async () => { const keepAlive = true const result = await sdk.tx.balances.transferAll(dest, keepAlive, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -610,12 +610,12 @@ const main = async () => { const payee = "Staked" const result = await sdk.tx.staking.bond(value, payee, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -680,12 +680,12 @@ const main = async () => { const maxAdditional = new BN(10).pow(new BN(18)) // one Avail const result = await sdk.tx.staking.bondExtra(maxAdditional, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -747,12 +747,12 @@ const main = async () => { const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice//stash") const result = await sdk.tx.staking.chill(WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -815,12 +815,12 @@ const main = async () => { const stash = "5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY" // Alice Stash const result = await sdk.tx.staking.chillOther(stash, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -877,12 +877,12 @@ const main = async () => { ] const result = await sdk.tx.staking.nominate(targets, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -949,12 +949,12 @@ const main = async () => { const value = new BN(10).pow(new BN(18)) // one Avail const result = await sdk.tx.staking.unbond(value, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1020,12 +1020,12 @@ const main = async () => { const blocked = false const result = await sdk.tx.staking.validate(commission, blocked, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } @@ -1104,12 +1104,12 @@ const main = async () => { const bouncer: string = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" // Alice const result = await sdk.tx.nominationPools.create(amount, root, nominator, bouncer, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1196,12 +1196,12 @@ const main = async () => { WaitFor.BlockInclusion, account, ) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1273,12 +1273,12 @@ const main = async () => { const poolId = 1 const result = await sdk.tx.nominationPools.join(amount, poolId, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1349,12 +1349,12 @@ const main = async () => { const poolId = 1 const result = await sdk.tx.nominationPools.nominate(poolId, validators, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1415,12 +1415,12 @@ const main = async () => { const bondExtra = { FreeBalance: amount } as BondExtra const result = await sdk.tx.nominationPools.bondExtra(bondExtra, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1488,12 +1488,12 @@ const main = async () => { const metadata = "My Metadata" const result = await sdk.tx.nominationPools.setMetadata(poolId, metadata, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1555,12 +1555,12 @@ const main = async () => { const unbondingPoints = new BN(10).pow(new BN(18)).mul(new BN(100)) // 100 Avail const result = await sdk.tx.nominationPools.unbond(memberAccount, unbondingPoints, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1627,12 +1627,12 @@ const main = async () => { const poolId = 1 const result = await sdk.tx.nominationPools.chill(poolId, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1692,12 +1692,12 @@ const main = async () => { const permission: ClaimPermission = "PermissionlessAll" const result = await sdk.tx.nominationPools.setClaimPermission(permission, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1757,12 +1757,12 @@ const main = async () => { const poolId = 1 const result = await sdk.tx.nominationPools.claimCommission(poolId, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1824,12 +1824,12 @@ const main = async () => { const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") const result = await sdk.tx.nominationPools.claimPayout(WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1894,12 +1894,12 @@ const main = async () => { const other = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" // Bob const result = await sdk.tx.nominationPools.claimPayoutOther(other, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -1966,12 +1966,12 @@ const main = async () => { const newCommission: NewCommission = { amount: 25, payee: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" } const result = await sdk.tx.nominationPools.setCommission(poolId, newCommission, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -2042,12 +2042,12 @@ const main = async () => { WaitFor.BlockInclusion, account, ) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() @@ -2115,12 +2115,12 @@ const main = async () => { const state: PoolState = "Blocked" const result = await sdk.tx.nominationPools.setState(poolId, state, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/balances_tranfer_all.ts b/avail-js/docs/extrinsics/balances_tranfer_all.ts index fdb02777e..675a4d8d8 100644 --- a/avail-js/docs/extrinsics/balances_tranfer_all.ts +++ b/avail-js/docs/extrinsics/balances_tranfer_all.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -10,13 +10,12 @@ const main = async () => { const keepAlive = true const result = await sdk.tx.balances.transferAll(dest, keepAlive, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/balances_tranfer_all_no_wait.ts b/avail-js/docs/extrinsics/balances_tranfer_all_no_wait.ts new file mode 100644 index 000000000..5a3382477 --- /dev/null +++ b/avail-js/docs/extrinsics/balances_tranfer_all_no_wait.ts @@ -0,0 +1,17 @@ +import { SDK, Keyring } from "../../src/index" + +const main = async () => { + const providerEndpoint = "ws://127.0.0.1:9944" + const sdk = await SDK.New(providerEndpoint) + + // Input + const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") + const dest = "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" // Eve + const keepAlive = true + + const txHash = await sdk.tx.balances.transferAllNoWait(dest, keepAlive, account) + + console.log(txHash) + process.exit() +} +main() diff --git a/avail-js/docs/extrinsics/balances_tranfer_allow_death.ts b/avail-js/docs/extrinsics/balances_tranfer_allow_death.ts index 899175982..27cb3e965 100644 --- a/avail-js/docs/extrinsics/balances_tranfer_allow_death.ts +++ b/avail-js/docs/extrinsics/balances_tranfer_allow_death.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, BN } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -7,16 +7,15 @@ const main = async () => { // Input const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") const dest = "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" // Eve - const amount = new BN(10).pow(new BN(18)) // one Avail + const amount = SDK.oneAvail() const result = await sdk.tx.balances.transferAllowDeath(dest, amount, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/balances_tranfer_allow_death_no_wait.ts b/avail-js/docs/extrinsics/balances_tranfer_allow_death_no_wait.ts new file mode 100644 index 000000000..fd176bc72 --- /dev/null +++ b/avail-js/docs/extrinsics/balances_tranfer_allow_death_no_wait.ts @@ -0,0 +1,17 @@ +import { SDK, Keyring } from "../../src/index" + +const main = async () => { + const providerEndpoint = "ws://127.0.0.1:9944" + const sdk = await SDK.New(providerEndpoint) + + // Input + const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") + const dest = "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" // Eve + const amount = SDK.oneAvail() + + const txHash = await sdk.tx.balances.transferAllowDeathNoWait(dest, amount, account) + + console.log(txHash) + process.exit() +} +main() diff --git a/avail-js/docs/extrinsics/balances_tranfer_keep_alive.ts b/avail-js/docs/extrinsics/balances_tranfer_keep_alive.ts index ef163cddb..a03bf6321 100644 --- a/avail-js/docs/extrinsics/balances_tranfer_keep_alive.ts +++ b/avail-js/docs/extrinsics/balances_tranfer_keep_alive.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, BN } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -7,16 +7,15 @@ const main = async () => { // Input const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") const dest = "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" // Eve - const amount = new BN(10).pow(new BN(18)) // one Avail + const amount = SDK.oneAvail() const result = await sdk.tx.balances.transferKeepAlive(dest, amount, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/balances_tranfer_keep_alive_no_wait.ts b/avail-js/docs/extrinsics/balances_tranfer_keep_alive_no_wait.ts new file mode 100644 index 000000000..8a03fe912 --- /dev/null +++ b/avail-js/docs/extrinsics/balances_tranfer_keep_alive_no_wait.ts @@ -0,0 +1,17 @@ +import { SDK, Keyring } from "../../src/index" + +const main = async () => { + const providerEndpoint = "ws://127.0.0.1:9944" + const sdk = await SDK.New(providerEndpoint) + + // Input + const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") + const dest = "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" // Eve + const amount = SDK.oneAvail() + + const txHash = await sdk.tx.balances.transferKeepAliveNoWait(dest, amount, account) + + console.log(txHash) + process.exit() +} +main() diff --git a/avail-js/docs/extrinsics/da_create_application_key.ts b/avail-js/docs/extrinsics/da_create_application_key.ts index 3e0430346..5c42d4713 100644 --- a/avail-js/docs/extrinsics/da_create_application_key.ts +++ b/avail-js/docs/extrinsics/da_create_application_key.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -9,13 +9,12 @@ const main = async () => { const key = "MyAwesomeKey" const result = await sdk.tx.dataAvailability.createApplicationKey(key, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/da_create_application_key_no_wait.ts b/avail-js/docs/extrinsics/da_create_application_key_no_wait.ts new file mode 100644 index 000000000..7ebf33bd9 --- /dev/null +++ b/avail-js/docs/extrinsics/da_create_application_key_no_wait.ts @@ -0,0 +1,16 @@ +import { SDK, Keyring } from "../../src/index" + +const main = async () => { + const providerEndpoint = "ws://127.0.0.1:9944" + const sdk = await SDK.New(providerEndpoint) + + // Input + const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") + const key = "MyAwesomeKey" + + const txHash = await sdk.tx.dataAvailability.createApplicationKeyNoWait(key, account) + + console.log(txHash) + process.exit() +} +main() diff --git a/avail-js/docs/extrinsics/da_set_aplication_key.ts b/avail-js/docs/extrinsics/da_set_aplication_key.ts index c1cfdb3c7..105446c4e 100644 --- a/avail-js/docs/extrinsics/da_set_aplication_key.ts +++ b/avail-js/docs/extrinsics/da_set_aplication_key.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -10,13 +10,12 @@ const main = async () => { const newKey = "MyNewKeyAwesome2" const result = await sdk.tx.dataAvailability.setApplicationKey(oldKey, newKey, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/da_set_submit_data_fee_modifier.ts b/avail-js/docs/extrinsics/da_set_submit_data_fee_modifier.ts index f018c0623..107609a40 100644 --- a/avail-js/docs/extrinsics/da_set_submit_data_fee_modifier.ts +++ b/avail-js/docs/extrinsics/da_set_submit_data_fee_modifier.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, BN, sdkTransactions } from "avail-js-sdk" +import { SDK, WaitFor, Keyring, sdkTransactions } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -7,18 +7,17 @@ const main = async () => { // Input const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") const modifier = { - weightMaximumFee: new BN("10").pow(new BN("18")), + weightMaximumFee: SDK.oneAvail(), weightFeeDivider: 20, } as sdkTransactions.DispatchFeeModifier const result = await sdk.tx.dataAvailability.setSubmitDataFeeModifier(modifier, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/da_submit_block_length_proposal.ts b/avail-js/docs/extrinsics/da_submit_block_length_proposal.ts index ea518096a..2bd95a2c8 100644 --- a/avail-js/docs/extrinsics/da_submit_block_length_proposal.ts +++ b/avail-js/docs/extrinsics/da_submit_block_length_proposal.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -10,13 +10,12 @@ const main = async () => { const cols = 128 const result = await sdk.tx.dataAvailability.submitBlockLengthProposal(rows, cols, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/da_submit_data.ts b/avail-js/docs/extrinsics/da_submit_data.ts index 41e14b894..5a67793d8 100644 --- a/avail-js/docs/extrinsics/da_submit_data.ts +++ b/avail-js/docs/extrinsics/da_submit_data.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring, TransactionOptions } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -8,13 +8,14 @@ const main = async () => { const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") const data = "My Awesome Data" - const result = await sdk.tx.dataAvailability.submitData(data, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + const options: TransactionOptions = { app_id: 1 } + const result = await sdk.tx.dataAvailability.submitData(data, WaitFor.BlockInclusion, account, options) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/da_submit_data_no_wait.ts b/avail-js/docs/extrinsics/da_submit_data_no_wait.ts new file mode 100644 index 000000000..be39fc956 --- /dev/null +++ b/avail-js/docs/extrinsics/da_submit_data_no_wait.ts @@ -0,0 +1,17 @@ +import { SDK, Keyring, TransactionOptions } from "../../src/index" + +const main = async () => { + const providerEndpoint = "ws://127.0.0.1:9944" + const sdk = await SDK.New(providerEndpoint) + + // Input + const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") + const data = "My Awesome Data" + + const options: TransactionOptions = { app_id: 1 } + const txHash = await sdk.tx.dataAvailability.submitDataNoWait(data, account, options) + + console.log(txHash) + process.exit() +} +main() diff --git a/avail-js/docs/extrinsics/nomination_pools_bond_extra.ts b/avail-js/docs/extrinsics/nomination_pools_bond_extra.ts index 2fb5523d6..255c273e0 100644 --- a/avail-js/docs/extrinsics/nomination_pools_bond_extra.ts +++ b/avail-js/docs/extrinsics/nomination_pools_bond_extra.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, BondExtra, BN } from "avail-js-sdk" +import { SDK, WaitFor, Keyring, BondExtra, BN } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -6,16 +6,16 @@ const main = async () => { // Input const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") - const amount = new BN(10).pow(new BN(18)).mul(new BN(10000)) // 10_000 Avail + const amount = SDK.oneAvail().mul(new BN(10000)) // 10_000 Avail const bondExtra = { FreeBalance: amount } as BondExtra const result = await sdk.tx.nominationPools.bondExtra(bondExtra, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_chill.ts b/avail-js/docs/extrinsics/nomination_pools_chill.ts index 12ccacfe0..ccda267a4 100644 --- a/avail-js/docs/extrinsics/nomination_pools_chill.ts +++ b/avail-js/docs/extrinsics/nomination_pools_chill.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -9,12 +9,12 @@ const main = async () => { const poolId = 1 const result = await sdk.tx.nominationPools.chill(poolId, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_claim_commission.ts b/avail-js/docs/extrinsics/nomination_pools_claim_commission.ts index 84bba5c2f..930963ad2 100644 --- a/avail-js/docs/extrinsics/nomination_pools_claim_commission.ts +++ b/avail-js/docs/extrinsics/nomination_pools_claim_commission.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -9,12 +9,12 @@ const main = async () => { const poolId = 1 const result = await sdk.tx.nominationPools.claimCommission(poolId, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_claim_payout.ts b/avail-js/docs/extrinsics/nomination_pools_claim_payout.ts index 70c2a54a1..cd6981f6f 100644 --- a/avail-js/docs/extrinsics/nomination_pools_claim_payout.ts +++ b/avail-js/docs/extrinsics/nomination_pools_claim_payout.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -8,12 +8,12 @@ const main = async () => { const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") const result = await sdk.tx.nominationPools.claimPayout(WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_claim_payout_other.ts b/avail-js/docs/extrinsics/nomination_pools_claim_payout_other.ts index c00df7a85..3cf069122 100644 --- a/avail-js/docs/extrinsics/nomination_pools_claim_payout_other.ts +++ b/avail-js/docs/extrinsics/nomination_pools_claim_payout_other.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -9,12 +9,12 @@ const main = async () => { const other = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" // Bob const result = await sdk.tx.nominationPools.claimPayoutOther(other, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_create.ts b/avail-js/docs/extrinsics/nomination_pools_create.ts index f1f2fe7c6..2ea8cbec1 100644 --- a/avail-js/docs/extrinsics/nomination_pools_create.ts +++ b/avail-js/docs/extrinsics/nomination_pools_create.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, BN } from "avail-js-sdk" +import { SDK, WaitFor, Keyring, BN } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -6,19 +6,19 @@ const main = async () => { // Input const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") - const amount = new BN(10).pow(new BN(18)).mul(new BN(10000)) // 10_000 Avail + const amount = SDK.oneAvail().mul(new BN(10000)) // 10_000 Avail const root: string = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" // Alice const nominator: string = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" // Alice const bouncer: string = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" // Alice const result = await sdk.tx.nominationPools.create(amount, root, nominator, bouncer, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_create_with_pool_id.ts b/avail-js/docs/extrinsics/nomination_pools_create_with_pool_id.ts index d6953d5c2..d80ab49c1 100644 --- a/avail-js/docs/extrinsics/nomination_pools_create_with_pool_id.ts +++ b/avail-js/docs/extrinsics/nomination_pools_create_with_pool_id.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, BN } from "avail-js-sdk" +import { SDK, WaitFor, Keyring, BN } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -6,7 +6,7 @@ const main = async () => { // Input const account = new Keyring({ type: "sr25519" }).addFromUri("//Bob") - const amount = new BN(10).pow(new BN(18)).mul(new BN(10000)) // 10_000 Avail + const amount = SDK.oneAvail().mul(new BN(10000)) // 10_000 Avail const root: string = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" // Alice const nominator: string = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" // Alice @@ -22,12 +22,12 @@ const main = async () => { WaitFor.BlockInclusion, account, ) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_join.ts b/avail-js/docs/extrinsics/nomination_pools_join.ts index a65c30d54..e60933f08 100644 --- a/avail-js/docs/extrinsics/nomination_pools_join.ts +++ b/avail-js/docs/extrinsics/nomination_pools_join.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, BN } from "avail-js-sdk" +import { SDK, WaitFor, Keyring, BN } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -6,16 +6,16 @@ const main = async () => { // Input const account = new Keyring({ type: "sr25519" }).addFromUri("//Bob") - const amount = new BN(10).pow(new BN(18)).mul(new BN(10000)) // 10_000 Avail + const amount = SDK.oneAvail().mul(new BN(10000)) // 10_000 Avail const poolId = 1 const result = await sdk.tx.nominationPools.join(amount, poolId, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_nominate.ts b/avail-js/docs/extrinsics/nomination_pools_nominate.ts index c939de186..de2be576b 100644 --- a/avail-js/docs/extrinsics/nomination_pools_nominate.ts +++ b/avail-js/docs/extrinsics/nomination_pools_nominate.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -13,12 +13,12 @@ const main = async () => { const poolId = 1 const result = await sdk.tx.nominationPools.nominate(poolId, validators, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_set_claim_permission.ts b/avail-js/docs/extrinsics/nomination_pools_set_claim_permission.ts index bb891a08b..047bcf17e 100644 --- a/avail-js/docs/extrinsics/nomination_pools_set_claim_permission.ts +++ b/avail-js/docs/extrinsics/nomination_pools_set_claim_permission.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, ClaimPermission } from "avail-js-sdk" +import { SDK, WaitFor, Keyring, ClaimPermission } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -9,12 +9,12 @@ const main = async () => { const permission: ClaimPermission = "PermissionlessAll" const result = await sdk.tx.nominationPools.setClaimPermission(permission, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_set_commission.ts b/avail-js/docs/extrinsics/nomination_pools_set_commission.ts index 74e3baf65..c03803ccd 100644 --- a/avail-js/docs/extrinsics/nomination_pools_set_commission.ts +++ b/avail-js/docs/extrinsics/nomination_pools_set_commission.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, NewCommission } from "avail-js-sdk" +import { SDK, WaitFor, Keyring, NewCommission } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -10,12 +10,12 @@ const main = async () => { const newCommission: NewCommission = { amount: 25, payee: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" } const result = await sdk.tx.nominationPools.setCommission(poolId, newCommission, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_set_metadata.ts b/avail-js/docs/extrinsics/nomination_pools_set_metadata.ts index 7192b5540..a568daef4 100644 --- a/avail-js/docs/extrinsics/nomination_pools_set_metadata.ts +++ b/avail-js/docs/extrinsics/nomination_pools_set_metadata.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -10,12 +10,12 @@ const main = async () => { const metadata = "My Metadata" const result = await sdk.tx.nominationPools.setMetadata(poolId, metadata, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_set_state.ts b/avail-js/docs/extrinsics/nomination_pools_set_state.ts index 8e8edbd70..d67ccf1ce 100644 --- a/avail-js/docs/extrinsics/nomination_pools_set_state.ts +++ b/avail-js/docs/extrinsics/nomination_pools_set_state.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, PoolState } from "avail-js-sdk" +import { SDK, WaitFor, Keyring, PoolState } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -10,12 +10,12 @@ const main = async () => { const state: PoolState = "Blocked" const result = await sdk.tx.nominationPools.setState(poolId, state, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_unbond.ts b/avail-js/docs/extrinsics/nomination_pools_unbond.ts index dcb501990..6613c9f61 100644 --- a/avail-js/docs/extrinsics/nomination_pools_unbond.ts +++ b/avail-js/docs/extrinsics/nomination_pools_unbond.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, BN } from "avail-js-sdk" +import { SDK, WaitFor, Keyring, BN } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -7,15 +7,15 @@ const main = async () => { // Input const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") const memberAccount = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" // Alice - const unbondingPoints = new BN(10).pow(new BN(18)).mul(new BN(100)) // 100 Avail + const unbondingPoints = SDK.oneAvail().mul(new BN(100)) // 100 Avail const result = await sdk.tx.nominationPools.unbond(memberAccount, unbondingPoints, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/nomination_pools_withdraw_unbonded.ts b/avail-js/docs/extrinsics/nomination_pools_withdraw_unbonded.ts index 310dd70c6..82a5dc51c 100644 --- a/avail-js/docs/extrinsics/nomination_pools_withdraw_unbonded.ts +++ b/avail-js/docs/extrinsics/nomination_pools_withdraw_unbonded.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -15,12 +15,12 @@ const main = async () => { WaitFor.BlockInclusion, account, ) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/staking_bond.ts b/avail-js/docs/extrinsics/staking_bond.ts index 8f4d5b4f0..2334fb750 100644 --- a/avail-js/docs/extrinsics/staking_bond.ts +++ b/avail-js/docs/extrinsics/staking_bond.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, BN } from "avail-js-sdk" +import { SDK, WaitFor, Keyring, BN } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -6,17 +6,16 @@ const main = async () => { // Input const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") - const value = new BN(100_000).mul(new BN(10).pow(new BN("18"))) // 100 000 Avail + const value = SDK.oneAvail().mul(new BN(100000)) // 100_000 Avail const payee = "Staked" const result = await sdk.tx.staking.bond(value, payee, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/staking_bond_extra.ts b/avail-js/docs/extrinsics/staking_bond_extra.ts index 662329e1c..b582da026 100644 --- a/avail-js/docs/extrinsics/staking_bond_extra.ts +++ b/avail-js/docs/extrinsics/staking_bond_extra.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, BN } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -6,16 +6,15 @@ const main = async () => { // Input const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice//stash") - const maxAdditional = new BN(10).pow(new BN(18)) // one Avail + const maxAdditional = SDK.oneAvail() const result = await sdk.tx.staking.bondExtra(maxAdditional, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/staking_chill.ts b/avail-js/docs/extrinsics/staking_chill.ts index 8a1a171da..1e843e994 100644 --- a/avail-js/docs/extrinsics/staking_chill.ts +++ b/avail-js/docs/extrinsics/staking_chill.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" const sdk = await SDK.New(providerEndpoint) @@ -7,13 +7,12 @@ const main = async () => { const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice//stash") const result = await sdk.tx.staking.chill(WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/staking_chill_other.ts b/avail-js/docs/extrinsics/staking_chill_other.ts index 0bedff0d8..c85afbe9f 100644 --- a/avail-js/docs/extrinsics/staking_chill_other.ts +++ b/avail-js/docs/extrinsics/staking_chill_other.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" const sdk = await SDK.New(providerEndpoint) @@ -8,13 +8,12 @@ const main = async () => { const stash = "5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY" // Alice Stash const result = await sdk.tx.staking.chillOther(stash, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/staking_nominate.ts b/avail-js/docs/extrinsics/staking_nominate.ts index 32dd4c3f2..039ccd9e5 100644 --- a/avail-js/docs/extrinsics/staking_nominate.ts +++ b/avail-js/docs/extrinsics/staking_nominate.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -12,13 +12,12 @@ const main = async () => { ] const result = await sdk.tx.staking.nominate(targets, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/staking_unbond.ts b/avail-js/docs/extrinsics/staking_unbond.ts index 700f24b8c..3f321e222 100644 --- a/avail-js/docs/extrinsics/staking_unbond.ts +++ b/avail-js/docs/extrinsics/staking_unbond.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring, BN } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -6,15 +6,15 @@ const main = async () => { // Input const account = new Keyring({ type: "sr25519" }).addFromUri("//Alice") - const value = new BN(10).pow(new BN(18)) // one Avail + const value = SDK.oneAvail() const result = await sdk.tx.staking.unbond(value, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/extrinsics/staking_validate.ts b/avail-js/docs/extrinsics/staking_validate.ts index 2cbac4868..c930a1af9 100644 --- a/avail-js/docs/extrinsics/staking_validate.ts +++ b/avail-js/docs/extrinsics/staking_validate.ts @@ -1,4 +1,4 @@ -import { SDK, WaitFor, Keyring } from "avail-js-sdk" +import { SDK, WaitFor, Keyring } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" @@ -10,13 +10,12 @@ const main = async () => { const blocked = false const result = await sdk.tx.staking.validate(commission, blocked, WaitFor.BlockInclusion, account) - if (result.isErr) { - console.log(result.reason) + if (result.isErr()) { + console.log(result.error.reason) process.exit(1) } - console.log(JSON.stringify(result, null, 2)) - + console.log(JSON.stringify(result.value, null, 2)) process.exit() } main() diff --git a/avail-js/docs/storage/da_app_keys.ts b/avail-js/docs/storage/da_app_keys.ts index 61cf942fa..cd28c3ed6 100644 --- a/avail-js/docs/storage/da_app_keys.ts +++ b/avail-js/docs/storage/da_app_keys.ts @@ -1,4 +1,4 @@ -import { SDK } from "avail-js-sdk" +import { SDK } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" diff --git a/avail-js/docs/storage/da_app_keys_iter.ts b/avail-js/docs/storage/da_app_keys_iter.ts index ca62fc37a..f9d6bd363 100644 --- a/avail-js/docs/storage/da_app_keys_iter.ts +++ b/avail-js/docs/storage/da_app_keys_iter.ts @@ -1,4 +1,4 @@ -import { SDK } from "avail-js-sdk" +import { SDK } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" diff --git a/avail-js/docs/storage/da_next_app_id.ts b/avail-js/docs/storage/da_next_app_id.ts index 51419c71f..96fd38f88 100644 --- a/avail-js/docs/storage/da_next_app_id.ts +++ b/avail-js/docs/storage/da_next_app_id.ts @@ -1,4 +1,4 @@ -import { SDK } from "avail-js-sdk" +import { SDK } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" diff --git a/avail-js/docs/storage/staking_active_era.ts b/avail-js/docs/storage/staking_active_era.ts index b9bad52b2..51b4f8a47 100644 --- a/avail-js/docs/storage/staking_active_era.ts +++ b/avail-js/docs/storage/staking_active_era.ts @@ -1,4 +1,4 @@ -import { SDK } from "avail-js-sdk" +import { SDK } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" diff --git a/avail-js/docs/storage/staking_bonded.ts b/avail-js/docs/storage/staking_bonded.ts index 0296ea8f6..e27a1d363 100644 --- a/avail-js/docs/storage/staking_bonded.ts +++ b/avail-js/docs/storage/staking_bonded.ts @@ -1,4 +1,4 @@ -import { SDK } from "avail-js-sdk" +import { SDK } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" diff --git a/avail-js/docs/storage/staking_bonded_iter.ts b/avail-js/docs/storage/staking_bonded_iter.ts index 7b548f41b..369fb3243 100644 --- a/avail-js/docs/storage/staking_bonded_iter.ts +++ b/avail-js/docs/storage/staking_bonded_iter.ts @@ -1,4 +1,4 @@ -import { SDK } from "avail-js-sdk" +import { SDK } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" diff --git a/avail-js/docs/storage/system_account.ts b/avail-js/docs/storage/system_account.ts index 051783a4f..4971e418f 100644 --- a/avail-js/docs/storage/system_account.ts +++ b/avail-js/docs/storage/system_account.ts @@ -1,4 +1,4 @@ -import { SDK } from "avail-js-sdk" +import { SDK } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" diff --git a/avail-js/docs/storage/system_account_iter.ts b/avail-js/docs/storage/system_account_iter.ts index 3d03cb1fc..d4ffbe3eb 100644 --- a/avail-js/docs/storage/system_account_iter.ts +++ b/avail-js/docs/storage/system_account_iter.ts @@ -1,4 +1,4 @@ -import { SDK } from "avail-js-sdk" +import { SDK } from "../../src/index" const main = async () => { const providerEndpoint = "ws://127.0.0.1:9944" diff --git a/avail-js/src/sdk/account.ts b/avail-js/src/sdk/account.ts index f57179dba..7abce29a1 100644 --- a/avail-js/src/sdk/account.ts +++ b/avail-js/src/sdk/account.ts @@ -15,7 +15,7 @@ export interface AccountBalance { } export class Account { - waitFor: WaitFor.BlockInclusion = WaitFor.BlockInclusion + waitFor: WaitFor = WaitFor.BlockInclusion nonce: number | null = null appId: number | null = null @@ -24,18 +24,23 @@ export class Account { public keyring: KeyringPair, ) {} - setNonce(nonce: number | null) { - this.nonce = nonce + setNonce(value: number | null) { + this.nonce = value } - setAppId(appId: number | null) { - this.appId = appId + setAppId(value: number | null) { + this.appId = value + } + + setWaitFor(value: WaitFor) { + this.waitFor = value } async balanceTransfer(dest: string, value: BN): Promise> { const options = this.buildOptions() return await this.sdk.tx.balances.transferKeepAlive(dest, value, this.waitFor, this.keyring, options) } + async balanceTransferNoWait(dest: string, value: BN): Promise { const options = this.buildOptions() return await this.sdk.tx.balances.transferKeepAliveNoWait(dest, value, this.keyring, options) @@ -91,6 +96,10 @@ export class Account { return appKeys.sort((a, b) => a - b) } + oneAvail(): BN { + return SDK.oneAvail() + } + private buildOptions(): any { let options: any = {} if (this.nonce != null) { diff --git a/avail-js/src/sdk/index.ts b/avail-js/src/sdk/index.ts index 2abfcbbb4..28fc48bb6 100644 --- a/avail-js/src/sdk/index.ts +++ b/avail-js/src/sdk/index.ts @@ -2,6 +2,7 @@ import { ApiPromise } from "@polkadot/api" import { initialize } from "../chain" import { Transactions } from "./transactions" import { Utils } from "./utils" +import { BN } from "@polkadot/util" export * as sdkTransactions from "./transactions" export * as sdkTransactionData from "./transaction_data" @@ -22,6 +23,7 @@ export { ClaimPermission, NewCommission, PoolState, + TransactionOptions, } from "./transactions" export class SDK { @@ -39,4 +41,8 @@ export class SDK { this.tx = new Transactions(api) this.util = new Utils(api) } + + static oneAvail(): BN { + return new BN(10).pow(new BN(18)) + } } diff --git a/avail-js/src/sdk/transactions/index.ts b/avail-js/src/sdk/transactions/index.ts index addfa03ef..452c31d1e 100644 --- a/avail-js/src/sdk/transactions/index.ts +++ b/avail-js/src/sdk/transactions/index.ts @@ -5,7 +5,7 @@ import { DataAvailability } from "./da" import { NominationPools } from "./nomination_pools" import { Multisig } from "./multisig" -export { WaitFor } from "./common" +export { WaitFor, TransactionOptions } from "./common" export { DispatchFeeModifier } from "./da" export { StakingRewardDestination } from "./staking" export { BondExtra, ClaimPermission, NewCommission, PoolState } from "./nomination_pools"