The most optimal way to interact with the Native API on The Root Network is via @polkadot/api package in combination with our package @therootnetwork/api. It provides web3 developers the ability to query and interact with The Root Network node using Javascript/Typescript. For installation instructions, see Install Native API.One of the most important things to understand about the @polkadot/api is that most interfaces are actually generated automatically when connected to a running node. This is quite a departure from other APIs in projects with static interfaces. While it may sound intimidating, this concept is actually a powerful feature present in any Substrate chain. It enables the API to be used in environments where the chain is customized.To unpack this, we will start with the metadata and explain what it actually provides, since it is critical to understand how to interact with the API and any underlying chain.
When the API connects to a node, one of the first things it does is retrieve the metadata and decorate the API based on the metadata information. The metadata effectively provides data in the form of api.<type>.<module>.<section> that fits into one of the following categories:
consts - All runtime constants, e.g. api.consts.balances.existentialDeposit. These are not functions; rather, accessing the endpoint immediately yields the result as defined.
query - All chain state, e.g. api.query.system.account(<accountId>).
tx - All extrinsics, e.g. api.tx.balances.transfer(<accountId>, <value>).
Additionally, the metadata also provides information on events. These are queryable via the api.query.system.events() interface and also appear on transactions. Both these cases are detailed later.None of the information contained within the api.{consts, query, tx}.<module>.<method> endpoints are hardcoded in the API. Rather, everything is fully decorated by what the metadata exposes and is, therefore, completely dynamic. This means that when you connect to different chains, the metadata and API decoration will change and the API interfaces will reflect what is available on the chain you are connected to.
Everything the API returns is a type with a consistent interface: Codec. This means that a Vec<u32> (an array of u32 values), as well as a Struct (an object) or an Enum, has the same consistent base interface. Specific types will have values based on the type - decorated and available.As a minimum, anything returned by the API, be it a Vec<...>, Option<...>, Struct or any normal type will always have the following methods - as defined on the Codec interface:
.eq(<other value>) - checks for equality against the other value. In all cases, it will accept “like” values, i.e. in the case of a number, you can pass a primitive (such as 1), a hex value (such as 0x01) or even a Unit8Array
toHex() - returns a hex-base representation of the value, always prefixed by 0x
toHuman() - returns Human-parsable JSON structure with values formatted as per the settings
toJSON() - returns a JSON-like representation of the value. This is generally used when calling JSON.stringify(...) on the value
toString() - returns a string representation. In some cases, this performs additional encoding, i.e. for Address, AccountId and AccountIndex, it will encode to the ss58 address
.toU8a() - returns a Uint8Array representation of the encoded value (generally exactly as passed to the node, where values are SCALE encoded)
Additionally, the following getters and utilities are available:
.isEmpty - true if the value is an all-empty value, i.e. 0 in for numbers, all-zero for Arrays (or anything Uint8Array), false is non-zero
.hash - a Hash (once again with all the methods above) that is a blake2-256 representation of the contained value
In addition to the api.[consts | query | tx] detailed above, the API, upon connecting to a chain, fills in some information and makes it available directly on the API interface. These include -
api.genesisHash - The genesisHash of the connected chain
api.runtimeMetadata - The metadata as retrieved from the chain
api.runtimeVersion - The chain runtime version (including specification/implementation versions and types)
The api.rpc.<section>.<method> provides low-level interfaces to read the chain state that’s not necessarily bound to the pallet storage. It’s also the commonplace to add additional data query for the custom pallets, e.g. api.rpc.tokenUri.
// Initialize the API as in previous sections...// Retrieve the chain nameconst chain = await api.rpc.system.chain();// Retrieve the latest headerconst lastHeader = await api.rpc.chain.getHeader();// Log the informationconsole.log(`${chain}: last block #${lastHeader.number} has hash ${lastHeader.hash}`);
It’s possible to subscribe to RPC calls and receive up-to-date data. For instance, subscribe to a new block height change.
...let count = 0;// Subscribe to the new headersconst unsubscribe = await api.rpc.chain.subscribeNewHeads((lastHeader) => { console.log(`${chain}: last block #${lastHeader.number} has hash ${lastHeader.hash}`); if (++count === 10) { unsubscribe(); }});
Since we are dealing with a subscription, we now pass a callback into the subscribeNewHeads function, and this will be triggered on each header as they are imported. The same pattern applies to each of the api.rpc.subscribe functions. As the last parameter, a callback should be provided to stream the latest data as it becomes available.In general, whenever we create a subscription, we would like to clean up after ourselves and unsubscribe. Assuming we only want to log the first 10 headers, the above example demonstrates the use of the unsubscribe() function.
The api.query.<pallet>.<method> interfaces are used to read the public storage in each available pallet. Behind the scenes, the API uses the metadata information provided to construct queries based on the location and parameters provided to generate state keys and then queries these via RPC.
// Initialize the API as in previous sections...// The actual address that we will useconst ADDR = '0xE04CC55ebEE1cBCE552f250e85c57B70B2E2625b';const [now, { nonce, data: balance }] = await Promise.all([ api.query.timestamp.now(), api.query.system.account(ADDR)]);console.log(`${now}: balance of ${balance.free} and a nonce of ${nonce}`);
Similar to RPC calls, sometimes it’s necessary to subscribe to the chain state to handle your application logic. Fortunately, the API provides a straightforward way to do that.
...// Retrieve the current timestamp via subscriptionconst unsubscribe = await api.query.timestamp.now((moment) => { console.log(`The last block has a timestamp of ${moment}`); // unsubscribe(); call to stop receiving updates});
Instead of the await returning the actual one-time value, it returns a subscription unsubscribe() function. This function can be used to stop the subscription and clean up any underlying RPC connections. The supplied callback will contain the value streamed from the node as it changes.
Transaction endpoints are exposed, as determined by the metadata, on the api.tx.<pallet>.<method> endpoint. These allow you to submit transactions for inclusion in blocks, whether it’s transfers, setting information or any other operation your chain supports.The Root Network supports the ECDSA key-pair standard. To submit a transaction, make sure you have a valid account with a small amount of XRP tokens to cover the transaction fee. Create a keyring instance as follows:
import { Keyring } from "@polkadot/keyring";import { stringToU8a, u8aToHex, hexToU8a } from "@polkadot/util";// create a keyring with some non-default values specifiedconst keyring = new Keyring({ type: "ethereum" });const seedU8a = hexToU8a(ALICE_PRIVATE_KEY);const alice = keyring.addFromSeed(seedU8a);
Once that is done, to transfer a balance from Alice to Bob as per the example above, use the code below:
...// Sign and send a transfer from Alice to Bobconst txHash = await api.tx.balances .transfer(BOB, 12345) .signAndSend(alice);// Show the hashconsole.log(`Submitted with hash ${txHash}`);
The result of this call is the transaction hash. This is a hash of the data; receiving it does not mean the transaction has been included. It only means that the hash has been accepted for propagation by the node.
Caution: Transaction hash in Substrate-based blockchain is generally unique within a block but not across the chain. Check out this article for more details.
Similar to api.rpc and api.query interfaces, it’s possible to subscribe to the transaction state change to determine if it’s been included in the block or not.
...// Make a transfer from Alice to Bob, waiting for inclusionconst unsubscribe = await api.tx.balances .transfer(BOB, 12345) .signAndSend(alice, (result) => { console.log(`Current status is ${result.status.type}`); if (result.status.isInBlock) { console.log(`Transaction included at blockHash ${result.status.asInBlock}`); } else if (result.status.isFinalized) { console.log(`Transaction finalized at blockHash ${result.status.asFinalized}`); unsubscribe(); } });
As per all previous subscriptions, the transaction subscription returns unsubscribe() and the actual method has a subscription callback. The result object has two parts: events (to be covered in the next section) and the status enum.When the status enum is in Finalized state (checked via isFinalized), the underlying value contains the block’s hash where the transaction has been finalized. Finalized will follow InBlock, which is the block where the transaction has been included. InBlock does not mean the block is finalized, but rather applies to the transaction state, where Finalized means that the transaction cannot be forked off the chain.
Any transaction will emit events. As a bare minimum, this will always be either a system.ExtrinsicSuccess or system.ExtrinsicFailed event for the specific transaction. These provide the overall execution result for the transaction, i.e. execution has succeeded or failed.Depending on the transaction sent, some other events may be emitted. For instance, for a balances.transfer this could include one or more of Transfer, NewAccount or ReapedAccount, as defined in the substrate balances event defaults.To display or act on these events, we can do the following:
...// Make a transfer from Alice to BOB, waiting for inclusionconst unsubscribe = await api.tx.balances .transfer(BOB, 12345) .signAndSend(alice, ({ events = [], status, txHash }) => { console.log(`Current status is ${status.type}`); if (status.isFinalized) { console.log(`Transaction included at blockHash ${status.asFinalized}`); console.log(`Transaction hash ${txHash.toHex()}`); // Loop through Vec<EventRecord> to display all events events.forEach(({ phase, event: { data, method, section } }) => { console.log(`\t' ${phase}: ${section}.${method}:: ${data}`); }); unsubscribe(); } });
Caution: Be aware that when a transaction status is isFinalized, it means it is included, but it may still have failed - for instance, if you try to send a larger amount that you have free, the transaction is included in a block. However, from an end-user perspective, the transaction failed since the transfer did not occur. In these cases, a system.ExtrinsicFailed event will be available in the events array.
The RPC endpoints expose weight/payment information that takes an encoded extrinsic and calculates the on-chain weight fees for it. A wrapper for this is available on the tx itself, taking exactly the same parameters as you would pass to a normal .signAndSend operation, specifically .paymentInfo(sender, <any options>). To expand on our previous example:
// construct a transactionconst transfer = api.tx.balances.transfer(BOB, 12345);// retrieve the payment infoconst { partialFee, weight } = await transfer.paymentInfo(alice);console.log(`transaction will have a weight of ${weight}, with ${partialFee.toHuman()} weight fees`);// send the txtransfer.signAndSend(alice, ({ events = [], status }) => { ... });
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"The Root Network","colors":{"primary":"#2E9ACD","light":"#2E9ACD","dark":"#2E9ACD"},"logo":{"light":"https://mintcdn.com/therootnetwork/xSexgVubiJ1uxjZZ/logo/light.svg?fit=max\u0026auto=format\u0026n=xSexgVubiJ1uxjZZ\u0026q=85\u0026s=f5b1f8efb6b8c489111f80d54204d428","dark":"https://mintcdn.com/therootnetwork/xSexgVubiJ1uxjZZ/logo/dark.svg?fit=max\u0026auto=format\u0026n=xSexgVubiJ1uxjZZ\u0026q=85\u0026s=171ddecd8b85e5c78417c52c2c0a5fe1","href":"https://www.therootnetwork.com/"},"favicon":"/favicon.svg","background":{"decoration":"gradient"},"navbar":{"links":[{"label":"Start Building","href":"https://www.therootnetwork.com/build"},{"label":"Start Staking","href":"https://staking.therootnetwork.com/dashboard"}]},"footer":{"socials":{"x":"https://twitter.com/TheRootNetwork","discord":"https://discord.gg/TheRootNetwork","github":"https://github.com/futureversecom/"}},"seo":{"metatags":{"og:image":"https://mintlify.s3.us-west-1.amazonaws.com/therootnetwork/images/trn-hero.png","twitter:card":"summary_large_image","twitter:image":"https://mintlify.s3.us-west-1.amazonaws.com/therootnetwork/images/trn-hero.png","twitter:site:domain":"docs.therootnetwork.com","apple-mobile-web-app-title":"The Root Network Docs"}},"fonts":{"heading":{"family":"Objektivmk","weight":700,"source":"https://cdn.prod.website-files.com/64b459a54c6aeb0b60898fe2/64b459a54c6aeb0b60898fe7_ObjektivMk1-Bold.woff","format":"woff"}},"integrations":{"gtm":{"tagId":"G-0CL0BBNSZZ"},"intercom":{"appId":"x0kxkkip"}},"navigation":{"global":{"anchors":[{"anchor":"Community","icon":"discord","href":"https://discord.gg/TheRootNetwork"},{"anchor":"Blog","icon":"newspaper","href":"https://www.therootnetwork.com/blog"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"therootnetwork","hasAudioNarration":false,"actualSubdomain":"therootnetwork","customDomains":["docs.therootnetwork.com"],"gitSource":{"type":"github","owner":"futureversecom","repo":"mintlify-trn-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"feedback":{"thumbs":true,"edits":true,"issues":true},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"REMOVE_BRANDING":{"status":"ENABLED"},"CONTEXTUAL_FEEDBACK":{"status":"ENABLED"},"CODE_SNIPPET_FEEDBACK":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6ae92485416fcb78afb0d944:success","clientVersion":"0.0.4111","searchFilterCounts":[{"language":"default","tag":"Build","count":75},{"language":"default","tag":"Native API","count":53},{"language":"default","tag":"API Reference","count":49},{"language":"default","tag":"Runtime Pallets","count":48},{"language":"default","tag":"Asset Register","count":20},{"language":"default","tag":"Learn","count":20},{"language":"default","tag":"Guides","count":10},{"language":"default","tag":"EVM API","count":10},{"language":"default","tag":"Features","count":9},{"language":"default","tag":"Runtime Precompiles","count":6}]},"assistantConfig":{},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"build/substrate/core-concepts","slug":"/build/substrate/core-concepts","pageMetadata":{"title":"Building with Native API","description":null,"href":"/build/substrate/core-concepts"},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`The most optimal way to interact with the Native API on The Root Network is via `,_jsx(_components.code,{children:`@polkadot/api`}),` package in combination with our package `,_jsx(_components.code,{children:`@therootnetwork/api`}),`. It provides web3 developers the ability to query and interact with The Root Network node using Javascript/Typescript. For installation instructions, see `,_jsx(_components.a,{href:`/build/substrate/api-package`,children:`Install Native API`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`One of the most important things to understand about the `,_jsx(_components.code,{children:`@polkadot/api`}),` is that most interfaces are actually generated automatically when connected to a running node. This is quite a departure from other APIs in projects with static interfaces. While it may sound intimidating, this concept is actually a powerful feature present in any Substrate chain. It enables the API to be used in environments where the chain is customized.`]}),`\n`,_jsx(_components.p,{children:`To unpack this, we will start with the metadata and explain what it actually provides, since it is critical to understand how to interact with the API and any underlying chain.`}),`\n`,_jsx(Heading,{level:`2`,id:`metadata`,children:`Metadata`}),`\n`,_jsxs(_components.p,{children:[`When the API connects to a node, one of the first things it does is retrieve the metadata and decorate the API based on the metadata information. The metadata effectively provides data in the form of `,_jsx(_components.code,{children:`api.\u003ctype>.\u003cmodule>.\u003csection>`}),` that fits into one of the following categories:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`consts`}),` - All runtime constants, e.g. `,_jsx(_components.code,{children:`api.consts.balances.existentialDeposit`}),`. These are not functions; rather, accessing the endpoint immediately yields the result as defined.`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`query`}),` - All chain state, e.g. `,_jsx(_components.code,{children:`api.query.system.account(\u003caccountId>)`}),`.`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`tx`}),` - All extrinsics, e.g. `,_jsx(_components.code,{children:`api.tx.balances.transfer(\u003caccountId>, \u003cvalue>)`}),`.`]}),`\n`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`Additionally, the metadata also provides information on `,_jsx(_components.code,{children:`events`}),`. These are queryable via the `,_jsx(_components.code,{children:`api.query.system.events()`}),` interface and also appear on transactions. Both these cases are detailed later.`]}),`\n`,_jsxs(_components.p,{children:[`None of the information contained within the `,_jsx(_components.code,{children:`api.{consts, query, tx}.\u003cmodule>.\u003cmethod>`}),` endpoints are hardcoded in the API. Rather, everything is fully decorated by what the metadata exposes and is, therefore, completely dynamic. This means that when you connect to different chains, the metadata and API decoration will change and the API interfaces will reflect what is available on the chain you are connected to.`]}),`\n`,_jsx(Heading,{level:`2`,id:`runtime-types`,children:`Runtime Types`}),`\n`,_jsxs(_components.p,{children:[`Everything the API returns is a type with a consistent interface: `,_jsx(_components.code,{children:`Codec`}),`. This means that a `,_jsx(_components.code,{children:`Vec\u003cu32>`}),` (an array of `,_jsx(_components.code,{children:`u32`}),` values), as well as a `,_jsx(_components.code,{children:`Struct`}),` (an object) or an `,_jsx(_components.code,{children:`Enum`}),`, has the same consistent base interface. Specific types will have values based on the type - decorated and available.`]}),`\n`,_jsxs(_components.p,{children:[`As a minimum, anything returned by the API, be it a `,_jsx(_components.code,{children:`Vec\u003c...>`}),`, `,_jsx(_components.code,{children:`Option\u003c...>`}),`, `,_jsx(_components.code,{children:`Struct`}),` or any normal type will always have the following methods - as defined on the `,_jsx(_components.code,{children:`Codec`}),` interface:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`.eq(\u003cother value>)`}),` - checks for equality against the other value. In all cases, it will accept “like” values, i.e. in the case of a number, you can pass a primitive (such as `,_jsx(_components.code,{children:`1`}),`), a hex value (such as `,_jsx(_components.code,{children:`0x01`}),`) or even a `,_jsx(_components.code,{children:`Unit8Array`})]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`toHex()`}),` - returns a hex-base representation of the value, always prefixed by `,_jsx(_components.code,{children:`0x`})]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`toHuman()`}),` - returns Human-parsable JSON structure with values formatted as per the settings`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`toJSON()`}),` - returns a JSON-like representation of the value. This is generally used when calling `,_jsx(_components.code,{children:`JSON.stringify(...)`}),` on the value`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`toString()`}),` - returns a string representation. In some cases, this performs additional encoding, i.e. for `,_jsx(_components.code,{children:`Address`}),`, `,_jsx(_components.code,{children:`AccountId`}),` and `,_jsx(_components.code,{children:`AccountIndex`}),`, it will encode to the ss58 address`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`.toU8a()`}),` - returns a `,_jsx(_components.code,{children:`Uint8Array`}),` representation of the encoded value (generally exactly as passed to the node, where values are SCALE encoded)`]}),`\n`]}),`\n`]}),`\n`,_jsx(_components.p,{children:`Additionally, the following getters and utilities are available:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`.isEmpty`}),` - `,_jsx(_components.code,{children:`true`}),` if the value is an all-empty value, i.e. `,_jsx(_components.code,{children:`0`}),` in for numbers, all-zero for Arrays (or anything `,_jsx(_components.code,{children:`Uint8Array`}),`), `,_jsx(_components.code,{children:`false`}),` is non-zero`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`.hash`}),` - a `,_jsx(_components.code,{children:`Hash`}),` (once again with all the methods above) that is a `,_jsx(_components.code,{children:`blake2-256`}),` representation of the contained value`]}),`\n`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`chain-defaults`,children:`Chain Defaults`}),`\n`,_jsxs(_components.p,{children:[`In addition to the `,_jsx(_components.code,{children:`api.[consts | query | tx]`}),` detailed above, the API, upon connecting to a chain, fills in some information and makes it available directly on the API interface. These include -`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`api.genesisHash`}),` - The genesisHash of the connected chain`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`api.runtimeMetadata`}),` - The metadata as retrieved from the chain`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`api.runtimeVersion`}),` - The chain runtime version (including specification/implementation versions and types)`]}),`\n`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`chain-state`,children:`Chain State`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`api.rpc.\u003csection>.\u003cmethod>`}),` provides low-level interfaces to read the chain state that’s not necessarily bound to the pallet storage. It’s also the commonplace to add additional data query for the custom pallets, e.g. `,_jsx(_components.code,{children:`api.rpc.tokenUri`}),`.`]}),`\n`,_jsx(CodeBlock,{numberOfLines:`11`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`11`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Initialize the API as in previous sections`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`...`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Retrieve the chain name`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` chain = `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api.rpc.system.chain();`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Retrieve the latest header`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` lastHeader = `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api.rpc.chain.getHeader();`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Log the information`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`${chain}: last block #${lastHeader.number} has hash ${lastHeader.hash}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`It’s possible to subscribe to RPC calls and receive up-to-date data. For instance, subscribe to a new block height change.`}),`\n`,_jsx(CodeBlock,{numberOfLines:`11`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`11`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`...`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` count = 0;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Subscribe to the new headers`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` unsubscribe = `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api.rpc.chain.subscribeNewHeads((lastHeader) => {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`${chain}: last block #${lastHeader.number} has hash ${lastHeader.hash}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (++count === 10) {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` unsubscribe();`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Since we are dealing with a subscription, we now pass a callback into the `,_jsx(_components.code,{children:`subscribeNewHeads`}),` function, and this will be triggered on each header as they are imported. The same pattern applies to each of the `,_jsx(_components.code,{children:`api.rpc.subscribe`}),` functions. As the last parameter, a callback should be provided to stream the latest data as it becomes available.`]}),`\n`,_jsxs(_components.p,{children:[`In general, whenever we create a subscription, we would like to clean up after ourselves and unsubscribe. Assuming we only want to log the first 10 headers, the above example demonstrates the use of the `,_jsx(_components.code,{children:`unsubscribe()`}),` function.`]}),`\n`,_jsx(Heading,{level:`2`,id:`chain-storage`,children:`Chain Storage`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`api.query.\u003cpallet>.\u003cmethod>`}),` interfaces are used to read the public storage in each available pallet. Behind the scenes, the API uses the metadata information provided to construct queries based on the location and parameters provided to generate state keys and then queries these via RPC.`]}),`\n`,_jsx(CodeBlock,{numberOfLines:`12`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`12`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Initialize the API as in previous sections`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`...`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// The actual address that we will use`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ADDR = `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'0xE04CC55ebEE1cBCE552f250e85c57B70B2E2625b'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [now, { nonce, data: balance }] = `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Promise.all([`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api.query.timestamp.now(),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api.query.system.account(ADDR)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]);`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`${now}: balance of ${balance.free} and a nonce of ${nonce}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Similar to RPC calls, sometimes it’s necessary to subscribe to the chain state to handle your application logic. Fortunately, the API provides a straightforward way to do that.`}),`\n`,_jsx(CodeBlock,{numberOfLines:`8`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`8`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`...`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Retrieve the current timestamp via subscription`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` unsubscribe = `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api.query.timestamp.now((moment) => {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`The last block has a timestamp of ${moment}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // unsubscribe(); call to stop receiving updates`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Instead of the `,_jsx(_components.code,{children:`await`}),` returning the actual one-time value, it returns a subscription `,_jsx(_components.code,{children:`unsubscribe()`}),` function. This function can be used to stop the subscription and clean up any underlying RPC connections. The supplied callback will contain the value streamed from the node as it changes.`]}),`\n`,_jsx(Heading,{level:`2`,id:`transaction`,children:`Transaction`}),`\n`,_jsxs(_components.p,{children:[`Transaction endpoints are exposed, as determined by the metadata, on the `,_jsx(_components.code,{children:`api.tx.\u003cpallet>.\u003cmethod>`}),` endpoint. These allow you to submit transactions for inclusion in blocks, whether it’s transfers, setting information or any other operation your chain supports.`]}),`\n`,_jsxs(_components.p,{children:[`The Root Network supports the ECDSA key-pair standard. To submit a transaction, make sure you have a valid account with a small amount of `,_jsx(_components.code,{children:`XRP`}),` tokens to cover the transaction fee. Create a `,_jsx(_components.code,{children:`keyring`}),` instance as follows:`]}),`\n`,_jsx(CodeBlock,{numberOfLines:`7`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { Keyring } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"@polkadot/keyring\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { stringToU8a, u8aToHex, hexToU8a } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"@polkadot/util\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// create a keyring with some non-default values specified`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` keyring = `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`new`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Keyring({ `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`type`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"ethereum\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` seedU8a = hexToU8a(ALICE_PRIVATE_KEY);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` alice = keyring.addFromSeed(seedU8a);`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`Once that is done, to transfer a balance from Alice to Bob as per the example above, use the code below:`}),`\n`,_jsx(CodeBlock,{numberOfLines:`8`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`8`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`...`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Sign and send a transfer from Alice to Bob`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` txHash = `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api.tx.balances`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .transfer(BOB, 12345)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .signAndSend(alice);`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Show the hash`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Submitted with hash ${txHash}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`The result of this call is the transaction hash. This is a hash of the data; receiving it does not mean the transaction has been included. It only means that the hash has been accepted for propagation by the node.`}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Caution`}),`: Transaction hash in Substrate-based blockchain is generally unique within a block but not across the chain. `,_jsx(_components.a,{href:`https://wiki.polkadot.network/docs/build-protocol-info#unique-identifiers-for-extrinsics`,children:`Check out this article`}),` for more details.`]})}),`\n`,_jsxs(_components.p,{children:[`Similar to `,_jsx(_components.code,{children:`api.rpc`}),` and `,_jsx(_components.code,{children:`api.query`}),` interfaces, it’s possible to subscribe to the transaction state change to determine if it’s been included in the block or not.`]}),`\n`,_jsx(CodeBlock,{numberOfLines:`14`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`14`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`...`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Make a transfer from Alice to Bob, waiting for inclusion`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` unsubscribe = `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api.tx.balances`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .transfer(BOB, 12345)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .signAndSend(alice, (result) => {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Current status is ${result.status.type}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (result.status.isInBlock) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Transaction included at blockHash ${result.status.asInBlock}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (result.status.isFinalized) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Transaction finalized at blockHash ${result.status.asFinalized}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` unsubscribe();`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`As per all previous subscriptions, the transaction subscription returns `,_jsx(_components.code,{children:`unsubscribe()`}),` and the actual method has a subscription callback. The `,_jsx(_components.code,{children:`result`}),` object has two parts: `,_jsx(_components.code,{children:`events`}),` (to be covered in the next section) and the `,_jsx(_components.code,{children:`status`}),` enum.`]}),`\n`,_jsxs(_components.p,{children:[`When the `,_jsx(_components.code,{children:`status`}),` enum is in `,_jsx(_components.code,{children:`Finalized`}),` state (checked via `,_jsx(_components.code,{children:`isFinalized`}),`), the underlying value contains the block’s hash where the transaction has been finalized. `,_jsx(_components.code,{children:`Finalized`}),` will follow `,_jsx(_components.code,{children:`InBlock`}),`, which is the block where the transaction has been included. `,_jsx(_components.code,{children:`InBlock`}),` does not mean the block is finalized, but rather applies to the transaction state, where `,_jsx(_components.code,{children:`Finalized`}),` means that the transaction cannot be forked off the chain.`]}),`\n`,_jsx(Heading,{level:`2`,id:`transaction-events`,children:`Transaction Events`}),`\n`,_jsxs(_components.p,{children:[`Any transaction will emit events. As a bare minimum, this will always be either a `,_jsx(_components.code,{children:`system.ExtrinsicSuccess`}),` or `,_jsx(_components.code,{children:`system.ExtrinsicFailed`}),` event for the specific transaction. These provide the overall execution result for the transaction, i.e. execution has succeeded or failed.`]}),`\n`,_jsxs(_components.p,{children:[`Depending on the transaction sent, some other events may be emitted. For instance, for a `,_jsx(_components.code,{children:`balances.transfer`}),` this could include one or more of `,_jsx(_components.code,{children:`Transfer`}),`, `,_jsx(_components.code,{children:`NewAccount`}),` or `,_jsx(_components.code,{children:`ReapedAccount`}),`, as defined in the substrate `,_jsx(_components.code,{children:`balances`}),` event defaults.`]}),`\n`,_jsx(_components.p,{children:`To display or act on these events, we can do the following:`}),`\n`,_jsx(CodeBlock,{numberOfLines:`19`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`19`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`...`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Make a transfer from Alice to BOB, waiting for inclusion`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` unsubscribe = `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` api.tx.balances`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .transfer(BOB, 12345)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .signAndSend(alice, ({ events = [], status, txHash }) => {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Current status is ${status.type}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (status.isFinalized) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Transaction included at blockHash ${status.asFinalized}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Transaction hash ${txHash.toHex()}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Loop through Vec\u003cEventRecord> to display all events`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` events.forEach(({ phase, event: { data, method, section } }) => {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`\\\\t' ${phase}: ${section}.${method}:: ${data}`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` unsubscribe();`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})}),`\n`]})})}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Caution`}),`: Be aware that when a transaction status is `,_jsx(_components.code,{children:`isFinalized`}),`, it means it is included, but it may still have failed - for instance, if you try to send a larger amount that you have free, the transaction is included in a block. However, from an end-user perspective, the transaction failed since the transfer did not occur. In these cases, a `,_jsx(_components.code,{children:`system.ExtrinsicFailed`}),` event will be available in the events array.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`payment-information`,children:`Payment Information`}),`\n`,_jsxs(_components.p,{children:[`The RPC endpoints expose weight/payment information that takes an encoded extrinsic and calculates the on-chain weight fees for it. A wrapper for this is available on the tx itself, taking exactly the same parameters as you would pass to a normal `,_jsx(_components.code,{children:`.signAndSend`}),` operation, specifically `,_jsx(_components.code,{children:`.paymentInfo(sender, \u003cany options>)`}),`. To expand on our previous example:`]}),`\n`,_jsx(CodeBlock,{numberOfLines:`10`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`10`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// construct a transaction`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` transfer = api.tx.balances.transfer(BOB, 12345);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// retrieve the payment info`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { partialFee, weight } = `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` transfer.paymentInfo(alice);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`console.log(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`transaction will have a weight of ${weight}, with ${partialFee.toHuman()} weight fees`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// send the tx`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`transfer.signAndSend(alice, ({ events = [], status }) => { ... });`})}),`\n`]})})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Building with Native API","description":null,"href":"/build/substrate/core-concepts"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Metadata","slug":"metadata","depth":2,"children":[]},{"title":"Runtime Types","slug":"runtime-types","depth":2,"children":[]},{"title":"Chain Defaults","slug":"chain-defaults","depth":2,"children":[]},{"title":"Chain State","slug":"chain-state","depth":2,"children":[]},{"title":"Chain Storage","slug":"chain-storage","depth":2,"children":[]},{"title":"Transaction","slug":"transaction","depth":2,"children":[]},{"title":"Transaction Events","slug":"transaction-events","depth":2,"children":[]},{"title":"Payment Information","slug":"payment-information","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"therootnetwork","siteName":"The Root Network","title":"Building with Native API - The Root Network","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2025-08-13T00:03:10.114Z","originalFileLocation":"build/substrate/core-concepts.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"application-name\" content=\"The Root Network\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/therootnetwork/223_vrjvu1ggaoMi/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/therootnetwork/223_vrjvu1ggaoMi/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/therootnetwork/223_vrjvu1ggaoMi/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/therootnetwork/223_vrjvu1ggaoMi/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/therootnetwork/223_vrjvu1ggaoMi/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/therootnetwork/223_vrjvu1ggaoMi/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/therootnetwork/223_vrjvu1ggaoMi/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/therootnetwork/223_vrjvu1ggaoMi/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/therootnetwork/223_vrjvu1ggaoMi/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Building with Native API - The Root Network\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"The Root Network\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.therootnetwork.com/build/substrate/core-concepts\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://mintlify.s3.us-west-1.amazonaws.com/therootnetwork/images/trn-hero.png\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Building with Native API - The Root Network\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://mintlify.s3.us-west-1.amazonaws.com/therootnetwork/images/trn-hero.png\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/therootnetwork/223_vrjvu1ggaoMi/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"The Root Network Docs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#2E9ACD\">\u003cmeta data-mint-head name=\"twitter:site:domain\" content=\"docs.therootnetwork.com\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.therootnetwork.com/build/substrate/core-concepts\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/build/substrate/core-concepts.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.therootnetwork.com/#organization\",\"name\":\"The Root Network\",\"url\":\"https://docs.therootnetwork.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/therootnetwork/xSexgVubiJ1uxjZZ/logo/light.svg?fit=max\u0026auto=format\u0026n=xSexgVubiJ1uxjZZ\u0026q=85\u0026s=f5b1f8efb6b8c489111f80d54204d428\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.therootnetwork.com#website\",\"name\":\"The Root Network\",\"url\":\"https://docs.therootnetwork.com\",\"publisher\":{\"@id\":\"https://docs.therootnetwork.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.therootnetwork.com/build/substrate/core-concepts#webpage\",\"url\":\"https://docs.therootnetwork.com/build/substrate/core-concepts\",\"name\":\"Building with Native API\",\"dateModified\":\"2025-08-13T00:03:10.114Z\",\"isPartOf\":{\"@id\":\"https://docs.therootnetwork.com#website\"},\"breadcrumb\":{\"@id\":\"https://docs.therootnetwork.com/build/substrate/core-concepts#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.therootnetwork.com/build/substrate/core-concepts#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Native API\",\"item\":\"https://docs.therootnetwork.com/build/substrate/api-package\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building with Native API\",\"item\":\"https://docs.therootnetwork.com/build/substrate/core-concepts\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.therootnetwork.com/build/substrate/core-concepts#article\",\"headline\":\"Building with Native API\",\"name\":\"Building with Native API\",\"url\":\"https://docs.therootnetwork.com/build/substrate/core-concepts\",\"mainEntityOfPage\":{\"@id\":\"https://docs.therootnetwork.com/build/substrate/core-concepts#webpage\"},\"image\":\"https://mintlify.s3.us-west-1.amazonaws.com/therootnetwork/images/trn-hero.png\",\"dateModified\":\"2025-08-13T00:03:10.114Z\",\"publisher\":{\"@id\":\"https://docs.therootnetwork.com/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.therootnetwork.com#website\"}}]}\u003c/script>","agentPointerHref":"/build/substrate/core-concepts.md","siteName":"The Root Network","nav":{"global":{"anchors":[{"anchor":"Community","icon":"discord","href":"https://discord.gg/TheRootNetwork"},{"anchor":"Blog","icon":"newspaper","href":"https://www.therootnetwork.com/blog"}]},"tabs":[{"tab":"Learn","pages":[{"title":"Learn","href":"/intro"}]},{"tab":"Build","groups":[{"group":"Build","pages":[{"title":"Getting Started","href":"/build/getting-started"},{"title":"Connecting to The Root Network","href":"/build/connecting-to-the-root-network"},{"title":"Test Faucet","url":"https://faucet.rootnet.cloud/","href":"/build/test-faucet"},{"title":"Curated Examples","url":"https://github.com/futureversecom/trn-examples","href":"/build/examples"},{"title":"Mainnet Rootscan Explorer","url":"https://rootscan.io/","href":"/build/rootscan-explorer"},{"title":"Testnet Rootscan Explorer","url":"https://porcini.rootscan.io/","href":"/build/testnet-rootscan-explorer"}]},{"group":"Native API","pages":[{"title":"Install Native API","description":null,"href":"/build/substrate/api-package"},{"title":"Building with Native API","href":"/build/substrate/core-concepts"},{"group":"Cookbook","pages":[{"title":"Primitives","description":null,"href":"/build/substrate/cookbook/primitives"},{"title":"Tokens","href":"/build/substrate/cookbook/tokens"}]},{"group":"API Reference","pages":[{"title":"JSON-RPC","href":"/build/substrate/api-reference/json-rpc"},{"group":"Runtime Pallets","pages":[{"title":"Assets","href":"/build/substrate/api-reference/runtime-pallets/assets"},{"title":"AssetsExt","href":"/build/substrate/api-reference/runtime-pallets/assetsext"},{"title":"Authorship","href":"/build/substrate/api-reference/runtime-pallets/authorship"},{"title":"Babe","href":"/build/substrate/api-reference/runtime-pallets/babe"},{"title":"Balances","href":"/build/substrate/api-reference/runtime-pallets/balances"},{"title":"Dex","href":"/build/substrate/api-reference/runtime-pallets/dex"},{"title":"Echo","href":"/build/substrate/api-reference/runtime-pallets/echo"},{"title":"ElectionProviderMultiPhase","href":"/build/substrate/api-reference/runtime-pallets/electionprovidermultiphase"},{"title":"Erc20Peg","href":"/build/substrate/api-reference/runtime-pallets/erc20peg"},{"title":"EthBridge","href":"/build/substrate/api-reference/runtime-pallets/ethbridge"},{"title":"Ethereum","href":"/build/substrate/api-reference/runtime-pallets/ethereum"},{"title":"Evm","href":"/build/substrate/api-reference/runtime-pallets/evm"},{"title":"EvmChainId","href":"/build/substrate/api-reference/runtime-pallets/evmchainid"},{"title":"FeeControl","href":"/build/substrate/api-reference/runtime-pallets/feecontrol"},{"title":"FeeProxy","href":"/build/substrate/api-reference/runtime-pallets/feeproxy"},{"title":"FuturePass","href":"/build/substrate/api-reference/runtime-pallets/futurepass"},{"title":"Grandpa","href":"/build/substrate/api-reference/runtime-pallets/grandpa"},{"title":"Historical","href":"/build/substrate/api-reference/runtime-pallets/historical"},{"title":"ImOnline","href":"/build/substrate/api-reference/runtime-pallets/imonline"},{"title":"LiquidityPools","href":"/build/substrate/api-reference/runtime-pallets/liquiditypool"},{"title":"MaintenanceMode","href":"/build/substrate/api-reference/runtime-pallets/maintenancemode"},{"title":"Marketplace","href":"/build/substrate/api-reference/runtime-pallets/marketplace"},{"title":"Multisig","href":"/build/substrate/api-reference/runtime-pallets/multisig"},{"title":"NFI","href":"/build/substrate/api-reference/runtime-pallets/nfi"},{"title":"NFT","href":"/build/substrate/api-reference/runtime-pallets/nft"},{"title":"NftPeg","href":"/build/substrate/api-reference/runtime-pallets/nftpeg"},{"title":"Offences","href":"/build/substrate/api-reference/runtime-pallets/offences"},{"title":"Preimage","href":"/build/substrate/api-reference/runtime-pallets/preimage"},{"title":"Recovery","href":"/build/substrate/api-reference/runtime-pallets/recovery"},{"title":"Proxy","href":"/build/substrate/api-reference/runtime-pallets/proxy"},{"title":"Scheduler","href":"/build/substrate/api-reference/runtime-pallets/scheduler"},{"title":"Session","href":"/build/substrate/api-reference/runtime-pallets/session"},{"title":"Sft","href":"/build/substrate/api-reference/runtime-pallets/sft"},{"title":"Staking","href":"/build/substrate/api-reference/runtime-pallets/staking"},{"title":"Sudo","href":"/build/substrate/api-reference/runtime-pallets/sudo"},{"title":"System","href":"/build/substrate/api-reference/runtime-pallets/system"},{"title":"SyloDataPermissions","href":"/build/substrate/api-reference/runtime-pallets/sylo-data-permissions"},{"title":"SyloActionPermissions","href":"/build/substrate/api-reference/runtime-pallets/sylo-action-permissions"},{"title":"SyloDataVerification","href":"/build/substrate/api-reference/runtime-pallets/sylo-data-verification"},{"title":"Timestamp","href":"/build/substrate/api-reference/runtime-pallets/timestamp"},{"title":"TokenApprovals","href":"/build/substrate/api-reference/runtime-pallets/tokenapprovals"},{"title":"TransactionPayment","href":"/build/substrate/api-reference/runtime-pallets/transactionpayment"},{"title":"TxFeePot","href":"/build/substrate/api-reference/runtime-pallets/txfeepot"},{"title":"Utility","href":"/build/substrate/api-reference/runtime-pallets/utility"},{"title":"VortexDistribution","href":"/build/substrate/api-reference/runtime-pallets/vortexdistribution"},{"title":"VoterList","href":"/build/substrate/api-reference/runtime-pallets/voterlist"},{"title":"Xls20","href":"/build/substrate/api-reference/runtime-pallets/xls20"},{"title":"XrplBridge","href":"/build/substrate/api-reference/runtime-pallets/xrplbridge"}]}]}]},{"group":"EVM API","pages":[{"title":"Install EVM API","href":"/build/evm/evm-package"},{"title":"Building with EVM API","href":"/build/evm/ethereum-vs-trn"},{"group":"Runtime Precompiles","pages":[{"title":"Decentralized Exchange","href":"/build/evm/runtime-precompiles/decentralized-exchange"},{"title":"Assets (ERC-20)","href":"/build/evm/runtime-precompiles/assets-erc-20"},{"title":"NFT (ERC-721)","href":"/build/evm/runtime-precompiles/nft-erc-721"},{"title":"SFT (ERC-1155)","href":"/build/evm/runtime-precompiles/sft-erc-1155"},{"title":"FeeProxy","href":"/build/evm/runtime-precompiles/feeproxy"},{"title":"FuturePass","href":"/build/evm/runtime-precompiles/futurepass"}]},{"group":"Cookbook","pages":[{"title":"How do I deploy a smart contract on The Root Network using hardhat?","href":"/build/evm/cookbook/smart-contract"},{"title":"Tokens","href":"/build/evm/cookbook/tokens"}]}]}]},{"tab":"Participate","pages":[{"title":"Participate","href":"/participate/running-a-node"}]},{"tab":"Pricing Sylo","pages":[{"title":"Pricing Sylo","href":"/pricing-sylo/overview"}]},{"tab":"Changelog","pages":[{"title":"Changelog","href":"/changelog"}]},{"tab":"Asset Register","pages":[{"title":"Asset Register","href":"/asset-register/introduction"}]},{"tab":"RootRewards","pages":[{"title":"RootRewards","href":"/rootrewards/overview"}]}]},"basePath":"","title":"Building with Native API - The Root Network","buildId":"dpl_DqYu5MPb49gWBBbUGgpHQUmCHY3P","deploymentId":"dpl_DqYu5MPb49gWBBbUGgpHQUmCHY3P","dynamics":[],"chunks":[]}