Learn more about MCWrapper.RPC
A simple .NET Core wrapper for the MultiChain Core blockchain library using JSON-RPC (RPC) clients.
Quick Start Notes:
- Start a new .NET Core project in Visual Studio 2019
- Using a Web App or Web API project is easiest since the Dependency Injection (DI) pipeline is already built.
- Install the latest stable version of MCWrapper.RPC from the NuGet Package Manager or use the Package Manager command
Install-Package MCWrapper.RPC
- Follow the steps to download and install the most recent stable version of MultiChain Community according to your operating system.
- Complete step one of Getting Started with MultiChain.
- We will need the following information from the new MultiChain node.
- The name of the new blockchain node.
- The new blockchain node admin's wallet address
- Run command > multichain-cli {blockchain name} listaddresses
- There should only be one address listed at this point.
- The new blockchain node's burn address
- Run command > multichain-cli {blockchain name} getinfo
- The JSON-RPC port number (printed to the console when -deamon command is used in step 4),
- The new MultiChain JSON-RPC username (usually multichainrpc by defaul),
- The new MultiChain JSON-RPC password
- The JSON-RPC username and password can be located in the multichain.conf file of the new MultiChain blockchain node.
- Next we will add MCWrapper.RPC to our application's service container pipeline.
Configuration for the MCWrapper.RPC clients is handled internally via the IOptions pattern.
The options pattern uses classes to represent groups of related settings. Visit the GitHub page to preview
the RpcOptions class.
Option #1 (preferred): This option is the most secure. Store the
MCWrapper.RPC RpcOptions as Environment Variables
that are automatically loaded on startup. Simply call the
AddMultiChainCoreRpcServices extension method after configuring
the environment. More information is available at our help page
for this topic.
// Startup class of the Web App or Web API
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
// ... previous code removed for brevity
services.AddMultiChainCoreRpcServices();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// ... remaining code removed for brevity
}
}
Option #2: This option is the still somewhat secure, depending on the
production environment. Store the MCWrapper.RPC RpcOptions as
variables on an external configuration file (appsettings.json) that are
automatically loaded on startup. Simply call the AddMultiChainCoreRpcServices
extension method and pass in the IConfiguration Configuration property after configuring the file.
More information is available at our help page for this topic.
// Startup class of the Web App or Web API
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
// ... previous code removed for brevity
services.AddMultiChainCoreRpcServices(Configuration);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// ... remaining code removed for brevity
}
}
Option #3: This option is not secure and should only be used in non-production
environments. Explicitly pass the MCWrapper.RPC RpcOptions as
arguments into the AddMultiChainCoreRpcServices extension method and they will be
loaded during startup. More information is available at our help page for this
topic.
Your values will differ from ours, the values listed below are just an example.
// Startup class of the Web App or Web API
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
// ... previous code removed for brevity
services.AddMultiChainCoreRpcServices(rpcOptions =>
{
rpcOptions.ChainAdminAddress = "1F5WvCAwc9sX6ZMJKE8GRZA6UQQPnxgB8FbU7t";
rpcOptions.ChainBurnAddress = "1XXXXXXXDXXXXXXX7bXXXXXXVsXXXXXXXCT2tS";
rpcOptions.ChainPassword = "EmjbtUBfbg2SikAXVnAJSQKmbeZhxbpSopsVKk58zrE";
rpcOptions.ChainUsername = "multichainrpc";
// localhost or a remote node's address eg. NewChain@192.168.1.1:7764
rpcOptions.ChainHostname = "localhost";
rpcOptions.ChainName = "NewChain";
rpcOptions.ChainRpcPort = 7764;
// default is HTTP if this is left empty
rpcOptions.ChainSslPath = string.Empty;
rpcOptions.ChainUseSsl = false;
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// ... remaining code removed for brevity
}
}
Environment Variables:
When using the parameterless AddMultiChainCoreRpcServices method MCWrapper.RPC will depend on the local machine's Environment
Variable store.
While depending on the Environment Variable store the following variable names are used.
- Environment variable names required by MCWrapper.RPC
- ChainAdminAddress (string)
- ChainBurnAddress (string)
- ChainName (string)
- ChainPassword (string)
- ChainUsername (string)
- ChainHostname (string)
- ChainRpcPort (int)
- ChainSslPath (string)
- ChainUseSsl (bool)
IConfiguration:
When using the IConfiguration argument along with the AddMultiChainCoreRpcServices method MCWrapper.RPC will depend on
an external JSON Configuration file, generally named appsettings.json.
The external JSON configration file should contain the following variable names along with
their values.
Your values will differ from ours, the values listed below are just an example.
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
// values required by RpcOptions when passing the,
// IConfiguration object to the AddMultiChainCoreCliServices method.
"ChainAdminAddress": "1F5WvCAwc9sX6ZMJKE8GRZA6UQQPnxgB8FbU7t",
"ChainBurnAddress": "1XXXXXXXDXXXXXXX7bXXXXXXVsXXXXXXXCT2tS",
"ChainName": "NewChain",
"ChainPassword": "EmjbtUBfbg2SikAXVnAJSQKmbeZhxbpSopsVKk58zrE",
"ChainUsername": "multichainrpc",
"ChainHostname": "localhost",
"ChainRpcPort": 7764,
"ChainSslPath": "",
"ChainUseSsl": false
}