Effortless SDK Integration: Mastering Wallets, NFTs and NFT Markets with C#

SDKVersionPackageFunction referenceObject reference
C#1.1Download linkDocumentation LinkDocumentation Link


This library should only be used server-side! In order to use the API, a Client-ID and Client-secret will be required. Which can be obtained via our business portal.

The following paragraphs provide examples of SDK initialization and usage. These code snippets assume you've already obtained the library from NuGet. Towards the end, you'll discover a practical code example illustrating how to create and retrieve wallets and NFTs using this C# SDK.

Initialising the API

string client_id = "YOUR_CLIENT_ID";
string client_secret = "YOUR_CLIENT_SECRET"; //This will either be a Staging or Production Secret
eVyEnvironment env = eVyEnvironment.staging; //Depends on your client secret

//API Provider (Handles the communication)
var provider = new DefaultServerProvider(client_id, client_secret);

//API Initialization
var result = await VenlyAPI.Initialize(provider, env);
if (result.Success) Console.WriteLine("Venly API Initialized!");
else throw result.Exception;

After the initialisation you can now start using functions from the exposed API products, Wallet, NFT and Market.

Processing Client Requests

The logic to process incoming requests from clients is also part of the SDK. Request coming from clients like Unity3D or Unreal Engine (using the SDK) will be of type VyRequestData. You can use the HandleRequest function from the Backend namespace to produce a fitting VyServerResponseDto that can be sent back to the Client.

//Optional, configure client access (allow/deny certain endpoints)
//ExecuteNativeTokenTransfer is by default not allowed to be called from the client
//but, you can opt to allow it anyway (pincode is required anyway)

//Process Client Requests
VyServerResponseDto response = await VenlyAPI.Backend.HandleRequest(incoming_request).AwaitResult();
//Return response to the client...

Handling Extension Requests

On the client side it is possible to make custom requests (Extension Requests). These Extensions offer a way to easily invoke server-side logic by calling a specific Extension function and providing it with optional content. Of course, the server must implement a mechanism to handle these custom requests, that's where Request Handlers come into play (VyRequestHandlerBase). The handler can be passed to the provider, and every extension request handled by the Backend.HandleRequest function will be relayed to your custom Request handler.

Custom Request Handler

internal class CustomRequestHandler : VyRequestHandlerBase
    public override VyTask<VyServerResponseDto> HandleExtension(VyRequestData requestData, object customData = null)
        //Retrieve Extension Parameters
        var extensionName = requestData.Uri;
        var extensionData = requestData.ContentStr;
        //Process the Extension Request...

        //Create a Response
        var response = new VyServerResponseDto
            Success = true,
            Data = "Give it some content",
            ErrorMessage = null,
            StatusCode = 200

        //Return the Response
        return VyTask<VyServerResponseDto>.Succeeded(response);

Registering the Handler

//API Provider (Handles the communication)
var customHandler = new CustomRequestHandler();
var provider = new DefaultServerProvider(client_id, client_secret, customHandler);

//Initialize the Venly API...

//Extension Request will now automatically be relayed to your CustomRequestHandler
//if you are using Backend.HandleRequest of course

Server-Side Usage Examples

Here's a brief code example that showcases the combined usage of the C# SDK with the Wallet API and NFT API for tasks like wallet creation and retrieval, accessing NFT contracts, and minting NFTs.

//Retrieve Wallets (WALLET API)
var wallets = await VenlyAPI.Wallet.GetWallets().AwaitResult();
Console.WriteLine($"{wallets.Length} wallet(s) retrieved\n");

////Or without await
//    .OnComplete(result => { ... })
//    .OnSuccess(wallets => { ... })
//    .OnFail(ex => ...)
//    .Finally(()=>...);

//Create Wallet (WALLET API | Server)
var createWalletParams = new VyCreateWalletRequest
    Chain = eVyChain.Matic,
    Description = "DEMO wallet from Examples Snippet",
    Identifier = "NEW-WALLET-TEST",
    WalletType = eVyWalletType.WhiteLabel,
    Pincode = "1234"

var newWallet = await VenlyAPI.Wallet.CreateWallet(createWalletParams).AwaitResult();
Console.WriteLine($"New wallet created ({newWallet.Chain}), id={newWallet.Id}");

//Retrieve Tokens For Specific Wallet (WALLET API | Client)
if (wallets.Length > 0)
    var walletInfo = wallets[0];
    var multiTokens = await VenlyAPI.Wallet.GetMultiTokenBalances(walletInfo.Chain, walletInfo.Id)
        $"{multiTokens.Length} tokens(s) [ERC1155/ERC721] found for wallet with id={walletInfo.Id}\n");

//Retrieve Contracts (NFT API | Client)
var contracts = await VenlyAPI.Nft.GetContracts().AwaitResult();
Console.WriteLine($"{contracts.Length} contract(s) retrieved\n");
if (!contracts.Any()) return;

//Retrieve TokenTypes (NFT API | Client)
var sourceContract = contracts[0];
var tokenTypes = await VenlyAPI.Nft.GetTokenTypes(sourceContract.Id).AwaitResult();
Console.WriteLine($"{tokenTypes.Length} TokenTypes found for Contract with id={sourceContract.Id}");
if (!tokenTypes.Any()) return;

//Mint Token
var sourceTokenType = tokenTypes[0];
var sourceAddress = wallets[0].Address;

var mintingParams = new VyMintTokensRequest()
    Destinations = new []
        new VyTokenDestinationDto()
            Address = sourceAddress,
            Amount = 1

var mintingResult = await VenlyAPI.Nft.MintTokens(sourceContract.Id, sourceTokenType.Id, mintingParams);
if (mintingResult.Success)
    var mintedTokenInfo = mintingResult.Data[0].MintedTokens[0];
        $"Token Minted! (tokenId={mintedTokenInfo.TokenId}, destination={mintedTokenInfo.Destination})");
else throw mintingResult.Exception;