XDC .Net SDK

XRC20 Token Integration

Get XRC20 token-related information from XDCSDKLib DLL by following the steps given below:
  1. 1.
    Install the latest version of Visual Studio with .Net core v3.1 in Windows Operating System.
  2. 2.
    Add all the supporting DLL files into the .Net core new project by adding project references. The DLL files:
    1. 1.
      Nethereum.Web3.dll
    2. 2.
      XDCSDKLib.dll
    3. 3.
      BouncyCastle.Crypto.dll
    4. 4.
      Common.Logging.Core.dll
    5. 5.
      Nethereum.ABI.dll
    6. 6.
      Nethereum.Accounts.dll
    7. 7.
      Nethereum.BlockchainProcessing.dll
    8. 8.
      Nethereum.Contracts.dll
    9. 9.
      Nethereum.HdWallet.dll
    10. 10.
      Nethereum.Hex.dll
    11. 11.
      Nethereum.JsonRpc.Client.dll
    12. 12.
      Nethereum.JsonRpc.RpcClient.dll
    13. 13.
      Nethereum.KeyStore.dll
    14. 14.
      Nethereum.Model.dll
    15. 15.
      Nethereum.RLP.dll
    16. 16.
      Nethereum.RPC.dll
    17. 17.
      Nethereum.Signer.dll
    18. 18.
      Nethereum.StandardTokenEIP20.dll
    19. 19.
      Nethereum.Util.dll
    20. 20.
      Newtonsoft.Json.dll
    21. 21.
      ERC721ContractLibrary.dll
  3. 3.
    We pushed all the above-listed DLLs into the branch “XDC-SDK-Supported-DLL’’.

Getting Started

Create an instance of the XRC20 token:
1
using XDCSDKLib;
2
IXRC20Token XRC20Token = new XRC20Token();
Copied!

Read methods

name
1
var name= await XRC20Token.GetTokenName(“contractAddress”, “BlockchainNetworkUrl”);
Copied!
symbol
1
var symbol= await XRC20Token. GetSymbol (“contractAddress”, “BlockchainNetworkUrl”);
Copied!
decimal
1
var decimal= await XRC20Token. GetDecimal (“contractAddress”, “BlockchainNetworkUrl”);
Copied!
TotalSupply
1
var supply= await XRC20Token. GetTotalSupply (“contractAddress”, “BlockchainNetworkUrl”);
Copied!
balanceOf
1
var balanceOf= await XRC20Token. GetBalanceOf (“contractAddress”, “BlockchainNetworkUrl”,”ownerAdddress”);
Copied!
Allowance
1
var allowance= await XRC20Token. GetAllowance (“contractAddress”, ”ownerAdddress”,“BlockchainNetworkUrl”,” addressSpender”);
Copied!

Write Methods

Approve
1
var approve=  await XRC20Token. Approve(“contractAddress”, ” addressSpender”,” allowanceValue”,“BlockchainNetworkUrl”,”OwnerprivateKey”);
Copied!
TransferFrom
1
var transferFrom= await XRC20Token. TransferFrom(“contractAddress”, ”OwnerAddress”,”addressTo”,” allowanceValue”,“BlockchainNetworkUrl”,”SpenderPrivateKey”);
Copied!
Transfer
1
var transfer= await XRC20Token. Transfer(“contractAddress”,”addressTo”,”tokenValue”,“BlockchainNetworkUrl”,”OwnerprivateKey”);
Copied!
IncreaseAllowance
1
var allowance= await XRC20Token. GetIncreasesAllowance (“contractAddress”,”OwnerAddress”,”addressSpender”,”increaseAllowance”,“BlockchainNetworkUrl”,”SpenderPrivateKey”);
Copied!
DecreaseAllowance
1
var allowance= await XRC20Token. GetDecreaseAllowance (“contractAddress”,”OwnerAddress”,”addressSpender”,”decreasesAllowance”,“BlockchainNetworkUrl”,”SpenderPrivateKey”);
Copied!
TransferXdcAmmount
1
var XdcAmmount= await XRC20Token. TransferXdcAmmount (“toAddress”,”amount”,“BlockchainNetworkUrl”,”ownerPrivateKey”);
Copied!

XRC721 Token Integration

Get XRC721 token-related information from XDCSDKLib DLL by following the steps given below:

Getting Started

Create an instance of the XRC20 token:
1
Using XDCSDKLib;
2
IXRC721Token xRC721Token = new XRC721Token();
Copied!

Read Methods

name
1
var name= await xRC721Token.GetTokenName (“contractAddress”, “BlockchainNetworkUrl”);
Copied!
symbol
1
var symbol= await xRC721Token. GetSymbol (“contractAddress”, “BlockchainNetworkUrl”);
Copied!
decimal
1
var decimal= await xRC721Token. GetDecimal (“contractAddress”, “BlockchainNetworkUrl”);
Copied!
TotalSupply
1
var supply= await xRC721Token. GetTotalSupply (“contractAddress”, “BlockchainNetworkUrl”);
Copied!
balanceOf
1
var balanceOf= await xRC721Token. GetBalanceOf (“contractAddress”, “ownerAdddress”, “BlockchainNetworkUrl”);
Copied!
tokenURI
1
var tokenURI= await xRC721Token. GetTokenURI (“contractAddress”, ”tokenId”,“BlockchainNetworkUrl”);
Copied!
ownerOf
1
var ownerOf= await xRC721Token. GetOwnerOf (“contractAddress”, ”tokenId”,“BlockchainNetworkUrl”);
Copied!
tokenOwnerbyIndex
1
var tokenOwnerbyIndex = await xRC721Token. GetTokenOfOwnerByIndex (“contractAddress”, ”ownerAddress”,”Index”,“BlockchainNetworkUrl”);
Copied!
TokenByIndex
1
var tokenIndex = await xRC721Token. GetTokenByIndex (“contractAddress”, ” tokenByIndex”,“BlockchainNetworkUrl”);
Copied!
GetApproved
1
var getApproved= await xRC721Token. GetApproved (“contractAddress”, ”tokenId”,“BlockchainNetworkUrl”);
Copied!
supportsInterface
1
var supportsInterface= await xRC721Token. SupportsInterface (“contractAddress”, byte[] InterfaceId ,“BlockchainNetworkUrl”);
Copied!

Write Methods

approve
1
var approve= await xRC721Token. Approve (“contractAddress”, “addresTo”,“tokenId”“BlockchainNetworkUrl”,”ownerPrivateKey”);
Copied!
SetApprovalforAll
1
var setApproveAll= await xRC721Token. SetApprovalforAll (“contractAddress”, “addresTo”,approved “BlockchainNetworkUrl”,”ownerPrivateKey”);
Copied!
IsApprovalforAll
1
var IsApprovalforAll= await xRC721Token. IsApprovalforAll (“contractAddress”, “OwnerAddress”,“operatorAddress”,“BlockchainNetworkUrl”,”ownerPrivateKey”);
Copied!
Transferfrom
1
var tranFrom= await xRC721Token. TransferFrom (“contractAddress”, “addresTo”,“tokenId”“BlockchainNetworkUrl”,”ownerPrivateKey”);
Copied!
SafeTransferFrom
1
var SafeTransferFrom = await xRC721Token. SafeTransferFrom (“contractAddress”,” fromAddress”,“addresTo”,“tokenId”“BlockchainNetworkUrl”,”ownerPrivateKey”);
Copied!

Create an XRC account

Create the XRC account using the following code:
1
IAccount account=new Account();
2
​
3
account.CreateAccount(“password”,”workingDirectory”);
4
​
5
var privateKey = account.PrivateKey;
6
​
7
var accountAddress= account.AccountAddress;
Copied!
Private Key can also be accessed from the working directory that is saved in the system by the following method:
1
Var privateKey= account.GetPrivateKey(“nameoffile”,”workingdirectory”,”password”);
Copied!

How to Publish the XDCSDKWebApi into the server?

  1. 1.
    Install the SDK .net core 3.1 version on the server and publish the supported DLL files into the virtual directory of the server. We pushed all the supported DLLs for publishing the XDCSDKWebAPI into the branch PublishDllForXDCWebApi.
  2. 2.
    As per requirements, change the URL of BlockNetworkChain into the appsettings.json file.
1
"XDCSDKUrl": {
2
"Url": "
3
https://rpc.apothem.network/
4
"
5
}
Copied!

Hardware requirements:

  • Operating system: Windows 10 or upper version, windows server latest.
  • Memory (RAM): minimum 8 GB
  • Processor: Core I3 or above.