Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api-contract/start/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const code = new CodePromise(api, metadata, wasm);
```

The newly generated `code` object lets you call `instantiate_with_code` without having to encode the data yourself.
You will need to provide values for the instantiation options. Getting accurate gas and storage deposit costs is possible by calling the [instantiate](http://localhost:8080/substrate/rpc#instantiaterequest-instantiaterequest-at-blockhash-contractinstantiateresult) RPC, which dry runs the instantiation and returns the outcome. For the scope of this tutorial we will use hardcoded values.
You will need to provide values for the instantiation options. Getting accurate gas and storage deposit costs is possible by calling the [instantiate](/substrate/rpc#instantiaterequest-instantiaterequest-at-blockhash-contractinstantiateresult) RPC, which dry runs the instantiation and returns the outcome. For the scope of this tutorial we will use hardcoded values.

Here is how you would retrieve the contract address after instantiation for an [ink! incrementer contract](https://github.com/paritytech/ink-examples/blob/main/incrementer/lib.rs), whose constructor signature looks like this: `new (initValue: i32)`

Expand Down
14 changes: 7 additions & 7 deletions docs/api/cookbook/tx.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ In addition to the `signAndSend` helper on transactions, `.paymentInfo` (with th
// address or locked/unlocked keypair) (When overrides are applied, e.g
// nonce, the format would be `paymentInfo(sender, { nonce })`)
const info = await api.tx.balances
.transfer(recipient, 123)
.transferKeepAlive(recipient, 123)
.paymentInfo(sender);

// log relevant info, partialFee is Balance, estimated for current
Expand All @@ -32,7 +32,7 @@ Assuming you are sending a tx via `.signAndSend`, the callback yields informatio

```js
api.tx.balances
.transfer(recipient, 123)
.transferKeepAlive(recipient, 123)
.signAndSend(sender, ({ status, events }) => {
if (status.isInBlock || status.isFinalized) {
events
Expand Down Expand Up @@ -62,7 +62,7 @@ As of the `@polkadot/api` 2.3.1 additional result fields are exposed. Firstly th

```js
api.tx.balances
.transfer(recipient, 123)
.transferKeepAlive(recipient, 123)
.signAndSend(sender, ({ status, events, dispatchError }) => {
// status would still be set, but in the case of error we can shortcut
// to just check it (so an error would indicate InBlock or Finalized)
Expand Down Expand Up @@ -150,8 +150,8 @@ Polkadot/Substrate provides a `utility.batch` method that can be used to send a
```js
// construct a list of transactions we want to batch
const txs = [
api.tx.balances.transfer(addrBob, 12345),
api.tx.balances.transfer(addrEve, 12345),
api.tx.balances.transferKeepAlive(addrBob, 12345),
api.tx.balances.transferKeepAlive(addrEve, 12345),
api.tx.staking.unbond(12345)
];

Expand All @@ -178,7 +178,7 @@ for (let i = 0; i < 10; i++) {

// send, just retrieving the hash, not waiting on status
const txhash = await api.tx.balances
.transfer(recipient, 123)
.transferKeepAlive(recipient, 123)
.signAndSend(sender, { nonce });
}
```
Expand All @@ -188,7 +188,7 @@ As a convenience function, the `accountNextIndex` can be omitted by specifying a
```js
for (let i = 0; i < 10; i++) {
const txhash = await api.tx.balances
.transfer(recipient, 123)
.transferKeepAlive(recipient, 123)
.signAndSend(sender, { nonce: -1 });
}
```
Expand Down
51 changes: 33 additions & 18 deletions docs/api/examples/promise/transfer-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,68 @@ Display the events that occur during a transfer by sending a value to a random a

```javascript
// Import the API & Provider and some utility functions
const { ApiPromise } = require('@polkadot/api');
import { ApiPromise } from "@polkadot/api";

// Import the test keyring (already has dev keys for Alice, Bob, Charlie, Eve & Ferdie)
const testKeyring = require('@polkadot/keyring/testing');
import { Keyring } from "@polkadot/keyring";

// Utility function for random values
const { randomAsU8a } = require('@polkadot/util-crypto');
import { randomAsU8a } from "@polkadot/util-crypto";

// Some constants we are using in this sample
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
const ALICE_MNEMONIC = "//Alice";
const AMOUNT = 10000;

async function main () {
async function main() {
// Create the API and wait until ready
const api = await ApiPromise.create();

// Create an instance of our testing keyring
// If you're using ES6 module imports instead of require, just change this line to:
// const keyring = testKeyring();
const keyring = testKeyring.default();

// Get the nonce for the admin key
const { nonce } = await api.query.system.account(ALICE);
const keyring = new Keyring({ type: "sr25519" });

// Find the actual keypair in the keyring
const alicePair = keyring.getPair(ALICE);
const alicePair = keyring.addFromMnemonic(ALICE_MNEMONIC);

// Get the nonce for the admin key
let nonce = (
await api.rpc.system.accountNextIndex(alicePair.address)
).toBigInt();

// Create a new random recipient
const recipient = keyring.addFromSeed(randomAsU8a(32)).address;

console.log('Sending', AMOUNT, 'from', alicePair.address, 'to', recipient, 'with nonce', nonce.toString());
console.log(
"Sending",
AMOUNT,
"from",
alicePair.address,
"to",
recipient,
"with nonce",
nonce.toString()
);

// Do the transfer and track the actual status
api.tx.balances
.transfer(recipient, AMOUNT)
.transferKeepAlive(recipient, AMOUNT)
.signAndSend(alicePair, { nonce }, ({ events = [], status }) => {
console.log('Transaction status:', status.type);
console.log("Transaction status:", status.type);

if (status.isInBlock) {
console.log('Included at block hash', status.asInBlock.toHex());
console.log('Events:');
console.log("Included at block hash", status.asInBlock.toHex());
console.log("Events:");

events.forEach(({ event: { data, method, section }, phase }) => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
console.log(
"\t",
phase.toString(),
`: ${section}.${method}`,
data.toString()
);
});
} else if (status.isFinalized) {
console.log('Finalized block hash', status.asFinalized.toHex());
console.log("Finalized block hash", status.asFinalized.toHex());

process.exit(0);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/api/examples/rxjs/06_make_transfer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function main () {
// Create a extrinsic, transferring 12345 units to Bob.
const subscription = api.tx.balances
// create transfer
.transfer(BOB, 12345)
.transferKeepAlive(BOB, 12345)
// Sign and send the transcation
.signAndSend(alice)
// Subscribe to the status updates of the transfer
Expand Down
2 changes: 1 addition & 1 deletion docs/api/examples/rxjs/09_transfer_events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function main () {
// Create a extrinsic, transferring 12345 units to Bob.
api.tx.balances
// Do the transfer
.transfer(recipient, AMOUNT)
.transferKeepAlive(recipient, AMOUNT)
// Sign and send it
.signAndSend(alicePair)
// And subscribe to the actual status
Expand Down
4 changes: 2 additions & 2 deletions docs/api/start/api.consts.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ console.log(api.consts.babe.epochDuration.toNumber());
// The amount required to create a new account
console.log(api.consts.balances.existentialDeposit.toNumber());

// The amount required per byte on an extrinsic
console.log(api.consts.transactionPayment.transactionByteFee.toNumber());
// Multiplier applied to operational extrinsic fees to add a "virtual tip" and boost their priority
console.log(api.consts.transactionPayment.operationalFeeMultiplier.toString());
```

Since these are constants and defined by the metadata, it is not a call, but rather the values immediately available - as you'll see in subsequent sections, there is no need for `await` on these, it immediately returns the type and value for you to work with.
Expand Down
4 changes: 2 additions & 2 deletions docs/api/start/api.tx.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ To start off, let's make a balance transfer from Alice to Bob.

// Sign and send a transfer from Alice to Bob
const txHash = await api.tx.balances
.transfer(BOB, 12345)
.transferKeepAlive(BOB, 12345)
.signAndSend(alice);

// Show the hash
console.log(`Submitted with hash ${txHash}`);
```

We have already become familiar with the `Promise` syntax that is used throughout the API, in this case it is no different. We construct a transaction by calling `balances.transfer(<accountId>, <value>)` with the required params and then as a next step we submit it to the node.
We have already become familiar with the `Promise` syntax that is used throughout the API, in this case it is no different. We construct a transaction by calling `balances.transferKeepAlive(<accountId>, <value>)` with the required params and then as a next step we submit it to the node.

As with all other API operations, the `to` params just needs to be "account-like" and the value params needs to be "number-like", the API will take care of encoding and conversion into the correct format.

Expand Down
6 changes: 3 additions & 3 deletions docs/api/start/api.tx.subs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const alice = keyring.addFromUri('//Alice');

// Make a transfer from Alice to BOB, waiting for inclusion
const unsub = await api.tx.balances
.transfer(BOB, 12345)
.transferKeepAlive(BOB, 12345)
.signAndSend(alice, (result) => {
console.log(`Current status is ${result.status}`);

Expand Down Expand Up @@ -47,7 +47,7 @@ To display or act on these events, we can do the following -
...
// Make a transfer from Alice to BOB, waiting for inclusion
const unsub = await api.tx.balances
.transfer(BOB, 12345)
.transferKeepAlive(BOB, 12345)
.signAndSend(alice, ({ events = [], status, txHash }) => {
console.log(`Current status is ${status.type}`);

Expand All @@ -74,7 +74,7 @@ The Polkadot/Substrate RPC endpoints exposes weight/payment information that tak

```js
// construct a transaction
const transfer = api.tx.balances.transfer(BOB, 12345);
const transfer = api.tx.balances.transferKeepAlive(BOB, 12345);

// retrieve the payment info
const { partialFee, weight } = await transfer.paymentInfo(alice);
Expand Down
2 changes: 1 addition & 1 deletion docs/api/start/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ When the API connects to a node, one of the first things it does is to retrieve

- [consts](../../substrate/constants.md) - All runtime constants, e.g. `api.consts.balances.existentialDeposit`. These are not functions, rather accessing the endpoint immediately yields the result as defined.
- [query](../../substrate/storage.md) - All chain state, e.g. `api.query.system.account(<accountId>)`.
- [tx](../../substrate/extrinsics.md) - All extrinsics, e.g. `api.tx.balances.transfer(<accountId>, <value>)`.
- [tx](../../substrate/extrinsics.md) - All extrinsics, e.g. `api.tx.balances.transferKeepAlive(<accountId>, <value>)`.

Additionally the metadata also provides information on [events](../../substrate/events.md), these are query-able via the `api.query.system.events()` interface and also appear on transactions... both these cases are detailed later.

Expand Down
4 changes: 2 additions & 2 deletions docs/api/start/types.create.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Circling back to metadata. There are two important things to remember when using

1. The functionality available, e.g. exposed on `api.query.*` is not hard-coded in the API, rather this is decorated from the chain metadata. So the metadata lets the API know which endpoints are available and what the type for those endpoints are.

2. When you supply a value to the API, internally it will convert that value to the correct type as expected by the chain, i.e. as determined by the metadata. This means that a function such as `balances.transfer(address: Address, value: Balance)` can take at least the following inputs, which are all converted to the correct types -
2. When you supply a value to the API, internally it will convert that value to the correct type as expected by the chain, i.e. as determined by the metadata. This means that a function such as `balances.transferKeepAlive(address: Address, value: Balance)` can take at least the following inputs, which are all converted to the correct types -

- `address` can be an `Address`, an `AccountId`, an `Uint8Array` publicKey, a hex publicKey or an ss58 formatted address;
- `value` can be a `Balance`, a value encoded in hex, a `BN` object, a base-10 string, a JS `number`, a JS `BigInt` or even a SCALE-encoded `Uint8Array`
Expand Down Expand Up @@ -131,7 +131,7 @@ console.log(three.asThree.isNone); // true
You may want to construct a `Call` type given a specific tx. Using create type is unneecessary `createType`, and it can be achieved by simply using the `method` key attached to a `tx`.

```js
const tx = await api.tx.balances.transfer(BOB, 12345);
const tx = await api.tx.balances.transferKeepAlive(BOB, 12345);
console.log('Hex = ', tx.method.toHex())
```

Expand Down
4 changes: 2 additions & 2 deletions docs/api/start/types.extend.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Extending types
---

Circling back to metadata, by default the metadata information (at this point in time), only returns the type names as they apply to any section, be it a call, event or query. As an example, this means that transfers are defined as `balances.transfer(AccountId, Balance)` with no details as to the mapping of the `Balance` type to a `u128`. (The underlying Polkadot/Substrate default)
Circling back to metadata, by default the metadata information (at this point in time), only returns the type names as they apply to any section, be it a call, event or query. As an example, this means that transfers are defined as `balances.transferKeepAlive(AccountId, Balance)` with no details as to the mapping of the `Balance` type to a `u128`. (The underlying Polkadot/Substrate default)

Therefore to cater for all types, a mapping is done in the [@polkadot/types library](https://github.com/polkadot-js/api/tree/master/packages/types/src/interfaces) to define each of the types and align with their underlying structures as it maps to a default Polkadot or Substrate chain.

Expand Down Expand Up @@ -237,7 +237,7 @@ const api = await ApiPromise.create({
});
```

Always look at customization and understand the impacts, replicating these changes between the node and the API. For the above the `Address` type is used in the construction of the `UncheckedExtrinsic` type, while the lookup type is applicable on transactions such as `balances.transfer(to: LookupSource, value: Balance)`
Always look at customization and understand the impacts, replicating these changes between the node and the API. For the above the `Address` type is used in the construction of the `UncheckedExtrinsic` type, while the lookup type is applicable on transactions such as `balances.transferKeepAlive(to: LookupSource, value: Balance)`


## Custom RPC
Expand Down
6 changes: 3 additions & 3 deletions docs/derives/derives.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Instead of manually fetching and processing blockchain data, developers can use

- **[alliance](#alliance)**

- **[bagsList](#bagsList)**
- **[bagsList](#bagslist)**

- **[balances](#balances)**

Expand All @@ -28,7 +28,7 @@ Instead of manually fetching and processing blockchain data, developers can use

- **[elections](#elections)**

- **[imOnline](#imOnline)**
- **[imOnline](#imonline)**

- **[membership](#membership)**

Expand All @@ -40,7 +40,7 @@ Instead of manually fetching and processing blockchain data, developers can use

- **[staking](#staking)**

- **[technicalCommittee](#technicalCommittee)**
- **[technicalCommittee](#technicalcommittee)**

- **[treasury](#treasury)**

Expand Down
2 changes: 1 addition & 1 deletion docs/extension/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ The api is able to retrieve the signer when `signAndSend` is called with the add
const account = allAccounts[0];

// here we use the api to create a balance transfer to some account of a value of 12344
const transferExtrinsic = api.tx.balances.transfer('5C5555yEXUcmEJ5kkcCMvdZjUo7NGJiQJMS7vZXEeoMhj3VQ', 123456)
const transferExtrinsic = api.tx.balances.transferKeepAlive('5C5555yEXUcmEJ5kkcCMvdZjUo7NGJiQJMS7vZXEeoMhj3VQ', 123456)

// to be able to retrieve the signer interface from this account
// we can use web3FromSource which will return an InjectedExtension type
Expand Down
2 changes: 1 addition & 1 deletion docs/extension/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ const injector = await web3FromAddress(SENDER);
// the API then calls the extension to present to the user and get it signed.
// Once complete, the api sends the tx + signature via the normal process
api.tx.balances
.transfer('5C5555yEXUcmEJ5kkcCMvdZjUo7NGJiQJMS7vZXEeoMhj3VQ', 123456)
.transferKeepAlive('5C5555yEXUcmEJ5kkcCMvdZjUo7NGJiQJMS7vZXEeoMhj3VQ', 123456)
.signAndSend(SENDER, { signer: injector.signer }, (status) => { ... });
```
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"@docusaurus/core": "2.4.3",
"@docusaurus/preset-classic": "2.4.3",
"@mdx-js/react": "^1.6.22",
"@polkadot/dev": "^0.78.13",
"@polkadot/typegen": "^15.10.2",
"clsx": "^1.2.1",
"@polkadot/dev": "^0.83.3",
"@polkadot/typegen": "^16.4.6",
"clsx": "^2.1.1",
"comment-parser": "^1.4.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
Loading