A DENTNet node implements a standard Substrate/Polkadot JSON-RPC API that allows you to interact both with your local node and the entire DENTNet network. For example, you can use an RPC method to read a stored value, submit a transaction, or request information about the chain like latest block, runtime version etc.
Accessing the API
The RPC API is reachable both via HTTP and WS for streaming applications, and the node exposes it by default on port 9944 on localhost. Since some methods provide access to core node operations you should not directly expose a node to the public Internet.
The API is most easily accessed and integrated using @polkadot-js/api but there are other tools such a Subxt for Rust.
To get a list of the available RPC methods, the node has an RPC endpoint called rpc_methods. You can call this method (and the others) using a tool like curl:
The most commonly used methods for someone interested in submitting transactions on DENTNet will be author_submitExtrinsic and author_submitAndWatchExtrinsic .
To use this you first need to create a signed transaction to use as a parameter. For example, to send 12345 DENTX from account A to B we first create the signed transaction.
Details of how transactions are created can be found in the Polkadot documentation at Transaction Construction
Using @polkadot/api to submit the same transaction is easier as the extrinsic can be created:
const { ApiPromise } =require('@polkadot/api');const { Keyring } =require('@polkadot/keyring');constPRIVKEY='0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a'constRECIPIENT='dx8TbX2EdNtU2qMhTyeKcReSPzXZFGTMnNDqgGaSnznVWw32k';asyncfunctionmain () {// Instantiate the APIconstwsProvider=newWsProvider('ws://127.0.0.1:9944/');constapi=awaitApiPromise.create({ provider: wsProvider });// Construct the keyring and add our keyconstkeyring=newKeyring({ type:'sr25519' });constsender=keyring.addFromUri(PRIVKEY);// Create a extrinsic, transferring 12345 DENTX units to recipientconsttransfer=api.tx.balances.transferAllowDeath(RECIPIENT,12345);consthash=awaittransfer.signAndSend(sender);console.log('Transfer sent with hash',hash.toHex());}main().catch(console.error).finally(() =>process.exit());
Note that private keys should never be directly embedded in code as in the above example but be handled securely.