How to use XinFin’s Open API to Build Your First DApp on XDC Network

  1. What’s a DApp?
  2. Why develop DApps on the XinFin Network?
  3. What tools do you require to deploy a DApp on the XinFin Network?
  4. What is XinFin’s API, and how does it work?
  • Decentralized, meaning that they are independent, and no one can control them as a group.
  • Deterministic, meaning they perform the same function irrespective of the environment in which they are executed.
  • Turing is complete, meaning the dapp can perform any action given the required resources.
  • Isolated, which means that they are executed in a virtual environment known as Ethereum Virtual Machine so that if the smart contract happens to have a bug, it won’t hamper the normal functioning of the blockchain network
  1. Zero downtime — -Once you deploy the smart contract at the core of your DApp that’s on the XinDin blockchain, the network is able to serve clients seeking to interact with the contract. Therefore, malicious actors cannot launch denial-of-service attacks targeting your DApps.
  2. Privacy — -When developing on the XinFin Network, you don’t need to provide real-world identity to deploy or interact with a DApp. Your XDC account is your login, and you just need a wallet to gain access.
  3. Resistance to censorship — — Within the XinFin Network, no single entity can block users from submitting transactions, deploying DApps, or reading data from the XinFin blockchain.
  4. Complete data integrity — — Thanks to the network’s cryptographic primitives, data stored on the XinFin blockchain is immutable and indisputable. As such, malicious actors cannot forge transactions or other data that has already been made public.
  5. Trustless computation/verifiable behavior — — Smart contracts on the network can be analyzed and are guaranteed to execute in predictable ways, and without the need to trust a central authority. This is unlike traditional models where we need to trust a central authority to protect vital information. A great example is the online banking system, where we have to trust that financial institutions won’t misuse or tamper with our financial information. Or, in some cases, get hacked by malicious actors.
  6. Numerous APIs — -The XinFin Network has 10 Different types of API, which can help developers build DApps on the Network.
  1. XinPay: The extension wallet allows users to store and manage account keys, broadcast transactions, send and receive Ethereum-based cryptocurrencies and tokens, and securely connect to decentralized applications. These transactions take place through a compatible web browser or the mobile app’s inbuilt browser.
  2. XinFin-Remix IDE: Thanks to a rich set of plugins that have intuitive GUIs, the open-source web and desktop application fosters a fast development cycle. The remix plays a key role in the entire contract development journey and serves as a safe playground for learning and teaching on the XinFin Network.
  1. Xinfin Accounts:
  • Externally-owned — controlled by anyone with the private keys
  • Contract — a smart contract deployed to the network, controlled by code.
  • Receive, hold and send XDC and XRC-20 tokens
  • Interact with deployed smart contracts
  • With externally-owned accounts, creating an account costs nothing, and transactions between externally-owned accounts can only be XDC or XRC-20 transfers. As well, externally-owned accounts can initiate transactions.
  • With contract accounts, creating accounts has costs since you’re using network storage, transactions from an external account to a contract account can trigger code that can execute many actions, such as transferring tokens or even creating a new contract. And, the account can only send transactions in response to receiving a transaction.
  • Nonce — a counter that indicates the number of transactions sent from the account. This ensures transactions are only processed once. In a contract account, this number represents the number of contracts created by the account
  • Balance — the number of Wei owned by this address. Wei is a denomination of XDC, and there are 1e+18 Wei per XDC.
  • CodeHash — this hash refers to the code of an account on the (EVM). Contract accounts have code fragments programmed in that can perform different operations. This EVM code gets executed if the account gets a message call. It cannot be changed, unlike the other account fields. All such code fragments are contained in the state database under their corresponding hashes for later retrieval. This hash value is known as a codeHash. For externally owned accounts, the codeHash field is the hash of an empty string.
  • StorageRoot — Sometimes known as a storage hash. A 256-bit hash of the root node of a Merkle Patricia trie that encodes the storage contents of the account (a mapping between 256-bit integer values), encoded into the trie as a mapping from the Keccak 256-bit hash of the 256-bit integer keys to the RLP-encoded 256-bit integer values. This trie encodes the hash of the storage contents of this account and is empty by default.
  • Externally-owned accounts and key pairs — -An account is made up of a cryptographic pair of keys: public and private. They help prove that a transaction was actually signed by the sender and prevent forgeries. Your private key is what you use to sign transactions, so it grants you custody over the funds associated with your account. You never really hold cryptocurrency, you hold private keys — the funds are always on the XinFin ledger. This prevents malicious actors from broadcasting fake transactions because you can always verify the sender of a transaction.
  • Let’s look at an example:
  • If Sam wants to send XDC from his externally-owned account to Billy’s account, Sam needs to create a transaction request and send it out to the XinFin network for verification. XinFin’s usage of public-key cryptography ensures that Sam can prove that he originally initiated the transaction request. Without cryptographic mechanisms, a malicious adversary Eve could simply publicly broadcast a request that looks something like “send 5 XDC from Sam’s account to Billy’s account,” and no one would be able to verify that it didn’t come from Sam.
  • Contract accounts
  • Recipient — the receiving address (if an externally-owned account, the transaction will transfer value. In a contract account, the transaction will execute the contract code.
  • Signature — the identifier of the sender. This is generated when the sender’s private key signs the transaction and confirms the sender has authorized the transaction.
  • Value — the amount of XDC to transfer from sender to recipient (in WEI, a denomination of XDC).
  • Data — an optional field to include arbitrary data
  • GasLimit — the maximum amount of gas units that can be consumed by the transaction. Units of gas represent computational steps.
  • MaxPriorityFeePerGas — the maximum amount of gas to be included as a tip to the Masternode.
  • MaxFeePerGas — the maximum amount of gas willing to be paid for the transaction (inclusive of baseFeePerGas and maxPriorityFeePerGas).
{from: “xdcEA674fdDe714fd979de3EdF0F56AA9716B898ec8”,to: “xdcac03bb73b6a9e108530aff4df5077c2b3d481e5a”,gasLimit: “21000”,maxFeePerGas: “300”maxPriorityFeePerGas: “10”nonce: “0”,value: “1000”,}
{“id”: 2,“jsonrpc”: “2.0”,“method”: “account_signTransaction”,“params”: [{“from”: “xdc1923f626bb8dc025849e00f99c25fe2b2f7fb0db”,“gas”: “0x55555”,“maxFeePerGas”: “0x1234”,“maxPriorityFeePerGas”: “0x1234”,“input”: “0xabcd”,“nonce”: “0x0”,“to”: “xdc07a565b7ed7d7a678680a4c162885bedbb695fe0”,“value”: “0x1234”}]}
{“jsonrpc”: “2.0”,“id”: 2,“result”: {“raw”: “0xf88380018203339407a565b7ed7d7a678680a4c162885bedbb695fe080a44401a6e4000000000000000000000000000000000000000000000000000000000000001226a0223a7c9bcf5531c99be5ea7082183816eb20cfe0bbc322e97cc5c7f71ab8b20ea02aadee6b34b45bb15bc42d9c09de4a6754e7000908da72d48cc7704971491663”,“tx”: {“nonce”: “0x0”,“maxFeePerGas”: “0x1234”,“maxPriorityFeePerGas”: “0x1234”,“gas”: “0x55555”,“to”: “xdc07a565b7ed7d7a678680a4c162885bedbb695fe0”,“value”: “0x1234”,“input”: “0xabcd”,“v”: “0x26”,“r”: “0x223a7c9bcf5531c99be5ea7082183816eb20cfe0bbc322e97cc5c7f71ab8b20e”,“s”: “0x2aadee6b34b45bb15bc42d9c09de4a6754e7000908da72d48cc7704971491663”,“hash”: “0xeba2df809e7a612a0a0d444ccfa5c839624bdc00dd29e3340d46df3870f8a30e”}}}
  • Once you send a transaction, cryptography generates a transaction hash:
  • The transaction is then broadcast to the network and included in a pool with lots of other transactions.
  • Your transaction will also get a block confirmation number. This is the number of blocks created since the block that your transaction was included in. The higher the number, the greater the certainty that the transaction was processed and recognized by the network. This is because sometimes the block your transaction was included in may not have made it into the chain.
  • The larger the block confirmation number, the more immutable the transaction is. So for higher value transactions, more block confirmations may be desired.
  • Timestamp — the time when the block was created.
  • BlockNumber — the length of the blockchain in blocks.
  • BaseFeePerGas — the minimum fee per gas required for a transaction to be included in the block.
  • Difficulty — the effort required to create the block.
  • MixHash — a unique identifier for that block.
  • ParentHash — the unique identifier for the block that came before (this is how blocks are linked in a chain).
  • Transactions — the transactions included in the block.
  • StateRoot — the entire state of the system: account balances, contract storage, contract code, and account nonces that are inside.
  • Nonce — a hash that, when combined with the mixHash, proves that the block has gone through XinFin Delegated Proof of Stake (XDPoS).

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

AMA interview with Island Collective : The Island Collective · VR metaverse on ICP

What’s Proof of Elapsed Time

GREED & XT.com AMA Q&A Review

We Built a Wind Sock

Trends in Ethereum | Is Ethereum Worth Buying?

coinspaid s

Celer Network Off-Chain Crypto Economics

Scaling Shoutout: FunFair Technologies

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ruslan wing

ruslan wing

More from Medium

What are XRC-721 and XRC-1155: Standards for Creating NFTs on XinFin Network

asalp launched on mainnet.

Band Protocol Staking is on ICONFi!

Ninth milestone — DAO