# Polkadot

Source: https://developers.bitgo.com/docs/polkadot

## Overview

Polkadot (DOT) is the native asset of the Polkadot blockchain. It utilizes:
- Nominated Proof-of-stake (NPoS) model
- Schnorrkel/Ristretto x25519 ("sr25519") signature algorithm

Polkadot is a blockchain platform that facilitates interoperability between different blockchains through its native cryptocurrency, DOT. Designed by Ethereum co-founder Gavin Wood, Polkadot enables cross-chain transfers of data and assets, allowing decentralized applications (DApps) to operate seamlessly. The Polkadot network has a primary blockchain named the "relay chain" and many user-created parallel chains called "parachains".

### Explorer
<a href="https://polkadot.subscan.io/" target="_blank" rel="noreferrer">https://polkadot.subscan.io/</a>


## Wallets Types

BitGo enables holding dot in the following wallet types:

| | Multisig Cold | Multisig Hot | MPC Cold | MPC Hot |
|-| ------------- | ------------ | -------- | ------- |
| **Custody** | ❌ | N//A | ✅ | N/A |
| **Self-Custody** | ✅ | N//A | N/A | ✅ |

## Ticker Symbols

| Mainnet | Testnet |
| ------- | ------- |
| DOT | TDOT |

## Faucet

You can use a faucet to obtain free testnet dot for development and testing purposes.

**Faucet:** <a href="https://wiki.polkadot.network/docs/learn-DOT?ref=cms.polkadot.network#getting-tokens-on-the-westend-testnet" target="_blank" rel="noreferrer">https://wiki.polkadot.network/docs/learn-DOT</a>


## Units

The smallest unit for the account balance on Substrate based blockchains (Polkadot, Kusama, and so on) is Planck
- 1 Planck =	0.0000000001 DOT
- 10^10 Planck = 1.0000000000 DOT

You can pass balances in string or integer format. However, BitGo recommends using string format to ensure values don't exceed the programmable number limit.

### Native Token

DOT is the native token of the Polkadot network in a similar way that BTC is the native token of Bitcoin or Ether is the native token of the Ethereum blockchain.

### Fees

<a href="https://wiki.polkadot.network/docs/learn-transaction-fees" target="_blank" rel="noreferrer">Polkadot</a> fees consists of three parts:

- Base fee: a fixed fee that the runtime applies to every transaction.
- Length fee: a fee that gets multiplied by the length of the transaction, in bytes.
- Weight fee: a fee for each, varying runtime function. Runtime implementers need to implement a conversion mechanism which determines the corresponding amount for the calculated weight.

The final fee can be summarized as:

`fee = base_fee + length_of_transaction_in_bytes * length_fee + weight_fee`

Additionally, a minimum deposit of 1 DOT is required to initialize a wallet.

##### Fee Multiplier

Polkadot can add an additional fee to transactions if the network becomes too busy and starts to decelerate the system. This fee can create an incentive to avoid the production of low priority or insignificant transactions.

The network calculates the final fee as:

```
final_fee = fee * fee_multiplier
```


### Create wallets

```shell cURL
LABEL="My Test Wallet"
PASSPHRASE="secretpassphrase1a5df8380e0e30"

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d "{ \"label\": \"$LABEL\", \"passphrase\": \"$PASSPHRASE\", \"multisigType\": \"tss\" }" \
http://$BITGO_EXPRESS_HOST/api/v2/tdot/wallet/generate
```
```javascript JavaScript
bitgo
  .coin('tdot')
  .wallets()
  .generateWallet({
    label: 'My Test Wallet',
    passphrase: 'secretpassphrase1a5df8380e0e30',
    multisigType: 'tss'
  })
  .then(function (wallet) {
    // print the new wallet
    console.dir(wallet);
  });
```


### Create Address

```shell cURL
WALLET=585c51a5df8380e0e3082e46

curl -X POST \
-H "Authorization: Bearer $ACCESS_TOKEN" \
https://app.bitgo-test.com/api/v2/tdot/wallet/$WALLET/address
```
```javascript JavaScript
bitgo
  .coin('tdot')
  .wallets()
  .getWallet({ id: '585c51a5df8380e0e3082e46' })
  .then(function (wallet) {
    return wallet.createAddress();
  })
  .then(function (newAddress) {
    // print new address details
    console.dir(newAddress);
  });
```

## Estimate Fee

```shell cURL
export COIN="tdot"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X GET \
 https://app.bitgo-test.com/api/v2/$COIN/tx/fee \
 -H 'Content-Type: application/json' \
 -H "Authorization: Bearer $ACCESS_TOKEN"

```
```js JavaScript
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');
const accessToken = '<YOUR_ACCESS_TOKEN>';
const coin = 'tdot';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });
  bitgo.coin(coin).feeEstimate({ numBlocks: 2 }, function callback(err, res) {
     console.dir(res);
  });
})();
```

## Transact

```shell cURL
export BITGO_EXPRESS_HOST="<YOUR_LOCALHOST>"
export COIN="tdot"
export WALLET_ID="<YOUR_WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export ADDRESS="<DESTINATION_ADDRESS>"
export AMOUNT="<AMOUNT_IN_BASE_UNITS>"
export WALLET_PASSPHRASE="<YOUR_WALLET_PASSPHRASE>"

curl -X POST \
  http://$BITGO_EXPRESS_HOST/api/v2/$COIN/wallet/$WALLET_ID/sendcoins \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "address": "'"$ADDRESS"'",
    "amount": "'"$AMOUNT"'",
    "walletPassphrase": "'"$WALLET_PASSPHRASE"'"
}'
```
```shell cURL (send to many)
export BITGO_EXPRESS_HOST="<YOUR_LOCALHOST>"
export COIN="tdot"
export WALLET_ID="<YOUR_WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export ADDRESS_1="<DESTINATION_ADDRESS_1>"
export ADDRESS_2="<DESTINATION_ADDRESS_2"
export AMOUNT_1="<AMOUNT_1_IN_BASE_UNITS>"
export AMOUNT_2="<AMOUNT_2_IN_BASE_UNITS>"
export WALLET_PASSPHRASE="<YOUR_WALLET_PASSPHRASE>"

curl -X POST \
  http://$BITGO_EXPRESS_HOST/api/v2/$COIN/wallet/$WALLET_ID/sendmany \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "recipients": [
    {
      "address": "'"$ADDRESS_1"'",
      "amount": "'"$AMOUNT_1"'"
    },
    {
      "address": "'"$ADDRESS_2"'",
      "amount": "'"$AMOUNT_2"'"
    }
  ],
    "walletPassphrase": "'"$WALLET_PASSPHRASE"'"
}'
```
```js JavaScript
const tx = await fundedWallet.send({
    address: `<DESTINATION_ADDRESS>`,
    amount: `<AMOUNT>`,
    walletPassphrase: process.env.PASSWORD as string,
  });
```
```js JavaScript (send to many)
let params = {
  recipients: [
    {
      amount: "<AMOUNT_1>",
      address: "<DESTINATION_ADDRESS_1>",
    },
    {
      amount: "<AMOUNT_2>",
      address: "<DESTINATION_ADDRESS_2>",
    },
  ],
  walletPassphrase: "<YOUR_WALLET_PASSPHRASE>",
};
wallet.sendMany(params).then(function (transaction) {
  // Print transaction details
  console.dir(transaction);
});
```


## Stake
Polkadot implements <a href="https://wiki.polkadot.network/docs/learn-consensus#nominated-proof-of-stake" target="_blank" rel="noreferrer">Nominated Proof-of-Stake (NPoS)</a>, a relatively novel and sophisticated mechanism to select the validators who the protocol allows to participate in its consensus protocol. The NPoS encourages DOT holders to participate as nominators.
