LoopringSharp 0.1.1
See the version list below for details.
dotnet add package LoopringSharp --version 0.1.1
NuGet\Install-Package LoopringSharp -Version 0.1.1
<PackageReference Include="LoopringSharp" Version="0.1.1" />
paket add LoopringSharp --version 0.1.1
#r "nuget: LoopringSharp, 0.1.1"
// Install LoopringSharp as a Cake Addin #addin nuget:?package=LoopringSharp&version=0.1.1 // Install LoopringSharp as a Cake Tool #tool nuget:?package=LoopringSharp&version=0.1.1
LoopringSharp
WARNING! The API Is currently under construction and not ready for use
What is?
A C# NuGet Package wrapper around the Loopring API endpoints to greatly simplify communication. It should theoretically be as simple as importing the package, creating a singleton client, and off to the races.
The what api?
The Loopring API https://docs.loopring.io/
How be do?
Basically it's just
LoopringSharp.Client client = new LoopringSharp.Client("<apiKey>","<loopring private key>","<ethereum private key>",<account id>, "<ethreum public address>", "<api url>");
More explicitly:
LoopringSharp.Client client = new LoopringSharp.Client("pJ3sU5kJ489fLmrewslkreownsbTunMK9fcusikhK6tn5nEDY4vvkWg8PgV2R","0x444444444444444444444444444444444444444444444444444444444444444","0x5555555555555555555555555555555555555555555555555555555555555555", 1, "0x6666666666666666666666666666666666666666", "https://uat2.loopring.io/");
var storageId = await client.StorageId(1);
The is also the simplified version:
LoopringSharp.Client client = new LoopringSharp.Client("<loopring private key>","<ethereum private key>","<api url>");
Which uses API calls within the constructor to gather the missing information.
The values above are stored in RAM, which means they could be read by specialist software. If you are making a secure app please use the LoopringSharp.SecureClient which doesn't store anything in memory.
For client applications (like say you want to make a windows charting application or similar), there are now two better alternatives: MetaMask and WalletConnect. You can instruct the API to connect to one of those two services in order to get the information it needs. This is very secure since the private wallet information is not stored in-memory but instead lives within a secure third party service that does all the transfer validation and signing.
LoopringAPI.Client client = new LoopringAPI.Client("<api url>");
var storageId = await client.StorageId(1);
In the future, I'll look into adding WalletConnect support as well
There are three keys that are needed to use the LoopringAPI endpoints. Some endpoints require none of those keys, some of them require all of them, so let me explain what they are.
- apiKey = Your Loopring Wallet API key. You can get this by exporting your loopring wallet info, it's the "ApiKey" field. You can also get it by using the ApiKey() method in the client
- l2Pk = Your Loopring Wallet Private Key. You can get this by exportin your loopring wallet info, it's the "PrivateKey" field. If using MetaMask or WalletConnect, this is filled in automatically as needed.
- l1Pk = This is your Etherium Private Key, the one tied to your Loopring wallet. It's not part of the export mentioned above, you'll need to figure out how to get it based on your needs. If using MetaMask or WalletConnect, this is filled in automatically as needed.
As for which endpoint requires what, I'll atempt to make a table bellow with all the API calls supported in this package and which keys are needed for which call
API Call | ApiKey | l1Pk | l2Pk | Description |
---|---|---|---|---|
Ticker | N | N | N | Gets the price information for any crypto pair available to trade on Loopring |
Timestamp | N | N | N | Returns the relayer's current time in millisecond |
GetAccountInfo | N | N | N | Returns data associated with the user's exchange account |
ExchangeInfo | N | N | N | Gets all sorts of properties about the exchange you're contacting |
GetMarkets | N | N | N | Get a list of all the markets available on the exchange |
GetTokens | N | N | N | Returns the configurations of all supported tokens, including Ether. |
GetDepth | N | N | N | Returns the order book of a given trading pair. |
GetCandlesticks | N | N | N | Return the candlestick data of a given trading pair. |
GetPrice | N | N | N | Fetches, for all the tokens supported by Loopring, their fiat price. |
GetTrades | N | N | N | Query latest trades with specified market |
ApiKey | N | N | Y | Get the ApiKey associated with the user's account |
DeleteOrder | Y | N | Y | Cancels a open exchange / swap order |
SubmitOrder | Y | N | Y | Submits a new exchange / swap order |
UpdateApiKey | Y | N | Y | Request a new ApiKey for this user account |
StorageId | Y | N | N | Fetches the next order id for a given sold token |
OffchainFee | Y | N | N | Get how much fee you need to pay right now to carry out a transaction of a specified type |
OrderDetails | Y | N | N | Gets the details of one specific order using the hashId |
OrdersDetails | Y | N | N | Gets a detailed list of multiple orders based on the filtering criteria |
CreateInfo | Y | N | N | Returns a list of Ethereum transactions from users for exchange account registration. |
UpdateInfo | Y | N | N | Returns a list Ethereum transactions from users for resetting exchange passwords. |
Transfer | Y | Y | Y | Send some tokens to anyone else on L2 |
RequestNewL2PrivateKey | Y | Y | Y | Generates a new L2 private key for your account. Does not return they key |
LoopringAPI.TestConsole
There is a test console in the project that shows off how to use some of the parts within the API. I was also using it for testing. The console is in .net 6 so be prepared for that (VS 2022 and C# 10)
The most important thing about the test console is that you need to run it for the first time and fill in the file as instructed in the error that gets thrown. LoopringSharp needs those Api Keys in order to run.
LoopringSharp.Layer2TransferExample
This is a windows forms app that basically sends crypto from your wallet to a destination of your choosing. The code is explained in detail in the comments so I encourage you to read through it and understand how it works. Be careful if selecting the real network (not the test net) as you will end up sending your own crypto to someone by mistake (hopefully to me 😄)
Secure client
The regular client has a security flaw in it, in that it stores the apiKey, l2Pk and L1Pk in memory within itself, in order to facilitate easier API calls. This is great for server-side aplications where you have full control of the machine on which the code is running, so there's no risk of someone trying to extract those keys from RAM with a RAM editor.
However, if creating a client application which runs on the users's hardware or on the web, it is recommended to use the secure client
LoopringSharp.SecureClient client = new LoopringSharp.SecureClient("https://uat2.loopring.io/");
var storageId = await client.StorageId("<YOUR API KEY HERE>","<YOUR ACCOUNT ID HERE>", 1);
The secure client does not accept the apiKey, l2Pk, l1Pk as properties, but rather requires them as parameters on every method that needs them. This means that the keys are not stored in memory within the API class and it is up to the developer to decide how they want to secure this very sensitive infomation.
The regular client also makes use of the SecureClient internally, just that it stores the three keys within itself so they are not provided every single time a method is called in the API, easing development a little.
Credits to
fudgey.eth - Creator of PoseidonSharp, without which it would be impossible to actually do transfers within this api. https://github.com/fudgebucket27/PoseidonSharp
Donations
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Nethereum.Signer.EIP712 (>= 4.1.1)
- Nethereum.Web3 (>= 4.1.1)
- Newtonsoft.Json (>= 13.0.1)
- Portable.BouncyCastle (>= 1.8.10)
- PoseidonSharp (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Removed the metamask and wallet connect stuff from the base package as it's not relevant here