Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Here all interaction SDKs are listed that are maintained for the Secret Network
A toolkit very similar to CosmJs that allows people to create and sign contract executions, integrate wallets and more.
Documentation for Secret.Js is separately hosted under: https://secretjs.scrt.network/
The Secret Software Development Kit (SDK) in Python is a simple library toolkit for building software that can interact with the Secret blockchain and provides simple abstractions over core data structures, serialization, key management, and API request generation.
Written in Python offering extensive support libraries
Versatile support for key management solutions
Exposes the Secret Rest API through LCD/REST client
See the full documentation, code and usage examples here: https://github.com/secretanalytics/secret-sdk-python
Shade protocol made their own JavaScript SDK to help people interact with specifically their Contracts. It serves as a great example for Contract Interaction or can be forked to make a similar SDK for your own application. https://github.com/securesecrets/shadejs
In this section we will provide examples to common usage patterns of Secret.NET
// Query the current count
Console.WriteLine("Querying contract for current count");
await secretClient.Query.Compute.QueryContract<string>(
contractAddress,
new { get_count = new { } },
contractCodeHash);using SecretNET;
using SecretNET.Common;
using SecretNET.Common.Storage;
using SecretNET.Tx;
// Select a storage provider for the wallet
// Docs: https://github.com/0xxCodemonkey/SecretNET#creating--initializing-the-wallet
var storageProvider = new AesEncryptedFileStorage("", "SuperSecurePassword");
var createWalletOptions = new CreateWalletOptions(storageProvider);
// Import wallet from mnemonic phrase
// Use key created snippet "Create a new Wallet"
Wallet wallet = null;
if (await storageProvider.HasPrivateKey())
{
var storedMnemonic = await storageProvider.GetFirstMnemonic();
Console.WriteLine("Use stored mnemonic: " + storedMnemonic);
wallet = await Wallet.Create(storedMnemonic, options: createWalletOptions);
Console.WriteLine("wallet.Address: " + wallet.Address);
}
// get infos from https://docs.scrt.network/secret-network-documentation/development/connecting-to-the-network
var gprcUrl = "https://grpc.testnet.secretsaturn.net";
var chainId = "pulsar-3";
// Create a connection to Secret Network node
// Pass in a wallet that can sign transactions
// Docs: https://github.com/0xxCodemonkey/SecretNET#creating--initializing-the-wallet
var secretClient = new SecretNetworkClient(gprcUrl, chainId, wallet: wallet);
var tx = await secretClient.Tx.Bank.Send(
toAddress: "secret1j8u7n4v93kjyqa7wzzrgjule8gh4adde36mnwd",
amount: 1000000,
denom: "uscrt",
txOptions: new TxOptions() { GasLimit = 2_000_000 }
);
Console.WriteLine("Transaction: ", tx);var permit = await secretClient.Permit.Sign(
owner: wallet.Address,
chainId: secretClient.ChainId,
permitName: "test",
allowedContracts: new string[] { contractAddress },
permissions: new PermissionType[] {
PermissionType.Owner,
PermissionType.Balance
});
var snip20Client = new SecretNET.Token.Snip20Client(secretClient); // SecretNET.Token
var query = await snip20Client.Query.GetBalance(contractAddress, permit: permit, codeHash: permitContractCodeHash);var permit = await secretClient.Permit.Sign(
owner: wallet.Address,
chainId: secretClient.ChainId,
permitName: "test",
allowedTokens: new string[] { "abcdef" },
permissions: new PermissionType[] {
PermissionType.Owner
});
var result = secretClient.Permit.Verify(
permit,
wallet.Address,
"abcdef",
new PermissionType[] { PermissionType.Owner }
);using SecretNET;
using SecretNET.Common;
using SecretNET.Common.Storage;
using System;
// Select a storage provider for the wallet
// Docs: https://github.com/0xxCodemonkey/SecretNET#creating--initializing-the-wallet
var storageProvider = new AesEncryptedFileStorage("", "SuperSecurePassword");
var createWalletOptions = new CreateWalletOptions(storageProvider);
// Create a new account
var wallet = await Wallet.Create(options: createWalletOptions);
// get infos from https://docs.scrt.network/secret-network-documentation/development/connecting-to-the-network
var gprcUrl = "https://grpc.testnet.secretsaturn.net";
var chainId = "pulsar-3";
// Create a readonly connection to Secret Network node (does not attach the wallet)
var secretClient = new SecretNetworkClient(gprcUrl, chainId, wallet: null); // without a wallet
var response = await secretClient.Query.Bank.Balance(wallet.Address);
Console.WriteLine("Mnemonic: " + (await storageProvider.GetMnemonic(wallet.Address)));
Console.WriteLine("Address: " + wallet.Address);
Console.WriteLine($"Balance: {(float.Parse(response.Amount) / 1000000f)} SCRT"); // 1,000,00 uscrt = 1 SCRTA Kotlin multiplatform Encryption and REST client for Secret Network utilizing gRPC gateway endpoints.
Supported Features:
Contract Queries
Simulate Contract Execution To Estimate Gas
Contract Execution (MsgExecuteContract)
Contract Code Upload (MsgStoreCode)
Contract Instantiate (MsgInstantiateContract)
Contract Migrate (MsgMigrateContract)
Contract Update Admin (MsgUpdateAdmin)
Contract Clear Admin (MsgClearAdmin)
Bank Send (MsgSend)
Web: Delegate signing transactions to Kepler or Metamask browser wallets
Supported Targets:
JVM
js
iOS
macOS
An experimental swift pacakge for use with iOS and macOS is available as well.
SecretNET.NFT is a layer on top of the Secret.NET which supports all methods of the reference implementation of the SNIP721 contract.
nuget install SecretNET.NFT
var snip721Client = new SecretNET.NFT.Snip721Client(secretClient); // SecretNET.NFT
var addMinterMsg = new SecretNET.NFT.AddMinterRequest(minters: new[] { "" });
var addMinter = await snip721Client.Tx.AddMinter(
msg: new SecretNET.NFT.MsgAddMinter(addMinterMsg, contractAddress, codeHash),
txOptions: new TxOptions() { GasLimit = 100_000 });TODO: linux
var mintNftMsg = SecretNET.NFT.MintNftRequest.Create(tokenId: "1");
var mintNft = await snip721Client.Tx.MintNft(
msg: new SecretNET.NFT.MsgMintNft(mintNftMsg, contractAddress, codeHash),
txOptions: new TxOptions() { GasLimit = 200_000 }); var transferNftMsg = new SecretNET.NFT.TransferNftRequest(recipient, tokenId);
var transferNft = await snip721Client.Tx.TransferNft(
msg: new SecretNET.NFT.MsgTransferNft(transferNftMsg, contractAddress, codeHash),
txOptions: new TxOptions() { GasLimit = 50_000 }); var permit = await secretClient.Permit.Sign(
owner: wallet.Address,
chainId: secretClient.ChainId,
permitName: "test",
allowedContracts: new string[] { contractAddress },
permissions: new PermissionType[] {
PermissionType.Owner
});
var tokens = await snip721Client.Query.GetTokens(contractAddress, wallet.Address, permit: permit, codeHash: codeHash);var txExec = await snip20Client.Tx.SetViewingKey(
contractAddress,
"hello",
txOptions: new TxOptions() { GasLimit = 100_000 });
var tokens = await snip721Client.Query.GetTokens(contractAddress, wallet.Address, viewingKey: "hello", codeHash: codeHash);SecretNET.Token is a layer on top of the Secret.NET which supports all methods of the reference implementation of the SNIP20 contract.
nuget install SecretNET.Token
Secret.NET (full port of the ) is a .NET SDK for writing applications that interact with the Secret Network blockchain.
Written in C# / .NET 6 including MAUI Support.
Can be used in MAUI Apps on Android, iOS, Windows and Mac.
Provides simple abstractions over core data structures.
var snip20Client = new SecretNET.Token.Snip20Client(secretClient);
var txExec = await snip20Client.Tx.Transfer(
contractAddress,
recipient,
amount, // int as string
codeHash,
txOptions: new TxOptions() { GasLimit = 5_000_000 }
);using SecretNET;
using SecretNET.Common;
using SecretNET.Common.Storage;
using SecretNET.Tx;
// Select a storage provider for the wallet
// Docs: https://github.com/0xxCodemonkey/SecretNET#creating--initializing-the-wallet
var storageProvider = new AesEncryptedFileStorage("", "SuperSecurePassword");
var createWalletOptions = new CreateWalletOptions(storageProvider);
// Import wallet from mnemonic phrase
// Use key created snippet "Create a new Wallet"
Wallet wallet = null;
if (await storageProvider.HasPrivateKey())
{
var storedMnemonic = await storageProvider.GetFirstMnemonic();
Console.WriteLine("Use stored mnemonic: " + storedMnemonic);
wallet = await Wallet.Create(storedMnemonic, options: createWalletOptions);
Console.WriteLine("wallet.Address: " + wallet.Address);
}
// get infos from https://docs.scrt.network/secret-network-documentation/development/connecting-to-the-network
var gprcUrl = "https://grpc.testnet.secretsaturn.net";
var chainId = "pulsar-3";
// Create a connection to Secret Network node
// Pass in a wallet that can sign transactions
// Docs: https://github.com/0xxCodemonkey/SecretNET#creating--initializing-the-wallet
var secretClient = new SecretNetworkClient(gprcUrl, chainId, wallet: wallet);
// Upload the wasm of a simple contract
byte[] wasmByteCode = File.ReadAllBytes(@"mysimplecounter.wasm.gz");
// MsgStoreCode
var msgStoreCodeCounter = new MsgStoreCode(
wasmByteCode,
source: "", // Source is a valid absolute HTTPS URI to the contract's source code, optional
builder: "" // Builder is a valid docker image name with tag, optional
);
var storeCodeResponse = await secretClient.Tx.Compute.StoreCode(msgStoreCodeCounter, new TxOptions() { GasLimit = 2_000_000 });
var codeId = storeCodeResponse.Response.CodeId;
// contract hash, useful for contract composition
var contractCodeHash = await secretClient.Query.Compute.GetCodeHashByCodeId(codeId);
// Create an instance of the Counter contract, providing a starting count
var msgInitContract = new MsgInstantiateContract(
codeId: codeId,
label: $"My Counter {codeId}",
initMsg: new { count = 100 },
codeHash: contractCodeHash); // optional but way faster
var initContractResponse = await secretClient.Tx.Compute.InstantiateContract(msgInitContract, new TxOptions() { GasLimit = 200_000 });
//Find the contract_address in the logs
var contractAddress = initContractResponse?.Response?.Address;
var msgExecuteContract = new MsgExecuteContract(
contractAddress: contractAddress,
msg: new { increment = new { } },
codeHash: contractCodeHash);
var tx = await secretClient.Tx.Compute.ExecuteContract(msgExecuteContract, new TxOptions() { GasLimit = 200_000 });var txExec = await snip20Client.Tx.Send(
contractAddress,
recipient,
amount, // int as string
codeHash,
txOptions: new TxOptions() { GasLimit = 5_000_000 }
);var txExec = await snip20Client.Tx.SetViewingKey(
contractAddress,
"hello",
txOptions: new TxOptions() { GasLimit = 100_000 });
var txQuery = await snip20Client.Query.GetBalance(
contractAddress,
viewingKey: "hello",
codeHash: codeHash
);var txQuery = await await snip20Client.Query.GetTokenInfo(
contractAddress,
codeHash: codeHash
);var txQuery = await snip20Client.Query.GetTransactionHistory(
contractAddress,
pageSize: 10,
viewingKey: "hello",
codeHash: codeHash
);Supports every possible message and transaction type.
Exposes every possible query type.
Handles input/output encryption/decryption for Secret Contracts.
The SDK has a wallet built in and does not currently require / support external wallets.
Custom APIs / clients for specific smart contracts can be easily created and the additional packages for tokens / SNIP20 or NFT / SNIP721 (see below) can serve as an example for this.
You can find the source code and full version of the docs at https://github.com/0xxCodemonkey/SecretNET/
In addition the following complementary packages are available, which act as a layer on top of the Secret.NET:
SecretNET.Token supports all methods of the reference implementation of the SNIP20 contract.
SecretNET.NFT supports all methods of the reference implementation of the SNIP721 contract.
All packages are available via NuGet and can be easily installed nuget.exe -CLI:
ℹ️ Secret.NET unfortunately cannot be connected to localsecret (Docker) yet, as the docker image currently does not provide an encrypted connection on gRPC-web port 9091. As far as I know, .NET cannot be connected to an unencrypted port via gRPC-web unless it offers HTTP/2 exclusively, which is not the case with localsecret (it also runs HTTP 1.1 on port 9091). See here and here.
.NET Multi-platform App UI (.NET MAUI) is a cross-platform framework for creating native mobile and desktop apps with C# and XAML.
Using .NET MAUI, you can develop apps that can run on Android, iOS, macOS, and Windows from a single shared code-base.
.NET MAUI is open-source and is the evolution of Xamarin.Forms, extended from mobile to desktop scenarios, with UI controls rebuilt from the ground up for performance and extensibility.
Using .NET MAUI, you can create multi-platform apps using a single project, but you can add platform-specific source code and resources if necessary. One of the key aims of .NET MAUI is to enable you to implement as much of your app logic and UI layout as possible in a single code-base.
.NET MAUI is for developers who want to:
Write cross-platform apps in XAML and C#, from a single shared code-base in Visual Studio.
Share UI layout and design across platforms.
Share code, tests, and business logic across platforms.
nuget install SecretNET
nuget install SecretNET.Token
nuget install SecretNET.NFTInstall-Package SecretNET
Install-Package SecretNET.Token
Install-Package SecretNET.NFT