Interacting with HyperVMs with a Javascript SDK #1084
Replies: 2 comments
-
Gave a major update to our SDK. We split our original SDK into two repos:
Also updated both the SDKs to make it compatible with both node and browser environments so it should work everywhere. I also created a simple React app that integrates the SDK to do some very basic things such as get health status, import private keys, transfer assets to other users, create asset, mint asset, etc. Check it out at https://github.com/kpachhai/nuklai-sdk-demo. This of course uses both Nuklai JS SDK and Hyperchain JS SDK. Very early demo of a working version of the React app that integrates with the SDK. Having this separation will make it easier for the hypersdk devs to contribute to the generic SDK(Hyperchain JS SDK) as this could be used by anyone to build their own SDK for their own custom VM. Any feedback is appreciated as always. |
Beta Was this translation helpful? Give feedback.
-
Nuklai Wallet [DEVNET] is liveWe've made significant progress on the Nuklai Wallet, which is live here. This implementation shows the practical application of our NuklaiVM built on Avalanche's HyperSDK The Nuklai Wallet itself is built with our Hyperchain JS SDK and Nuklai SDK, which we discussed in the last update from @kpachhai. It's been a journey getting here, and I wanted to share a little more detail on how our wallet works:. First off, the wallet supports all the basic operations you'd expect — sending and receiving our native NAI tokens, viewing transactions history, etc. But where it gets really interesting is with custom assets. You can also create and mint your own tokens right from the wallet: The current version of the wallet supports the following features:
These are achieved from the methods we implemented in the export declare class RpcService extends common.Api {
protected configNuklai: config.NodeConfig;
constructor(configNuklai: config.NodeConfig);
getTransactionInfo(getTransactionInfoParams: GetTransactionInfoParams): Promise<GetTransactionInfoResponse>;
getBalance(getBalanceParams: GetBalanceParams): Promise<GetBalanceResponse>;
getAssetInfo(getAssetInfoParams: GetAssetInfoParams): Promise<GetAssetInfoResponse>;
sendTransferTransaction(to: string, asset: string, amount: number, memo: string, authFactory: auth.AuthFactory, hyperApiService: services.RpcService, actionRegistry: chain.ActionRegistry, authRegistry: chain.AuthRegistry): Promise<string>;
sendCreateAssetTransaction(symbol: string, decimals: number, metadata: string, authFactory: auth.AuthFactory, hyperApiService: services.RpcService, actionRegistry: chain.ActionRegistry, authRegistry: chain.AuthRegistry): Promise<{
txID: string;
assetID: string;
}>;
sendMintAssetTransaction(to: string, asset: string, amount: number, authFactory: auth.AuthFactory, hyperApiService: services.RpcService, actionRegistry: chain.ActionRegistry, authRegistry: chain.AuthRegistry): Promise<string>;
} These methods are built into the Nuklai SDK to cater for the listed features in the wallet. Let's explore them more closely. Using the ExplorerWhen you visit Nuklai Wallet for the first time, you will see a popup informing you that the wallet is currently in the Alpha stage, and feedback is welcomed. Click on "Don't show this again" to continue. The first page is the Explorer page. On it, you will find recent activities ongoing on the Nuklai blockchain — newly produced blocks and their individual elements.
The number of active accounts on the Nuklai network, as well as the TPS and unit prices will be available in due time. Creating new assetsAs mentioned, the Nuklai Wallet supports the creation and minting of new, custom assets/tokens directly from the wallet. For token creation or minting to work, you must have enough gas fee in your wallet. You can get test NAI tokens in the Faucet page as explained later below. How it works:The const handleCreateAsset = useCallback(async (values) => {
setModalType("");
// Creating asset
const authFactory = auth.getAuthFactory(keyType, privateKey);
const { txID, assetID } = await sdk.rpcServiceNuklai.sendCreateAssetTransaction(
values.symbol,
values.decimals,
values.metadata || "{}",
authFactory,
sdk.rpcService,
sdk.actionRegistry,
sdk.authRegistry
);
setmyTokens(prev => [...prev, assetID]);
await waitForAssetConfirmation(assetID);
addAssetIDToStorage(assetID, txID, values.symbol);
addTransactionIDToStorage(txID);
createForm.resetFields();
getAllAssetsAndBalances();
}, [keyType, privateKey, addAssetIDToStorage, addTransactionIDToStorage, getAllAssetsAndBalances, createForm]);
The wallet the supports the minting of the supply of created assets through the `handleMintAsset` function, utilizing the `sdk.rpcServiceNuklai.sendMintAssetTransaction` method in `@nuklai/nuklai-js-sdk` to mint new tokens to the user's address. Once the additional supply has been minted, the new token supply balance is updated and reflected in the wallet.
const handleMintAsset = useCallback(async (values) => {
setModalType('');
// Minting asset
const authFactory = auth.getAuthFactory(keyType, privateKey);
const txID = await sdk.rpcServiceNuklai.sendMintAssetTransaction(
address,
selectedAsset.id,
values.amount,
authFactory,
sdk.rpcService,
sdk.actionRegistry,
sdk.authRegistry
);
addTransactionIDToStorage(txID);
await updateAssetBalance(selectedAsset.id, values.amount);
mintForm.resetFields();
setTimeout(() => getAllAssetsAndBalances(), 5000);
}, [keyType, privateKey, selectedAsset, addTransactionIDToStorage, updateAssetBalance, getAllAssetsAndBalances, mintForm]); Transferring tokensThe Nuklai wallet facilitates the transfer of tokens between two users by leveraging our In order to allow users securely transfer tokens, we constructed an AuthFactory builder using the sender's private key and use that instance to authorize the The
|
Beta Was this translation helpful? Give feedback.
-
We recently launched our devnet for Nuklai - a Layer 1 blockchain network built using HyperSDK. You can check out our documentation to learn more about it and how you can start interacting with the devnet via RPC endpoints or a CLI or Javascript SDK. For info regarding the devnet specifically, you can refer to https://docs.nukl.ai/nuklai-network/nuklai-testnet
We started to research HyperSDK about 6 months ago and before we knew it, we fell into a deep rabbit hole full of new ideas, new capabilities and very developer friendly way of building a layer 1 blockchain within a matter of days. I wrote an article talking about my own journey into the world of HyperSDK that was recently featured on Hackernoon.
Suffice to say, the entirety of the Nuklai team was hooked in to what HyperSDK had to offer and we wanted to do more. We wanted to spread awareness of our own journey and wanted to share a lot of the tools and resources that we use internally which led to the development of the Nuklai Javascript SDK.
While we were building our wallet for Nuklai, we stumbled upon an issue because there was no javascript SDK to interact with HyperVMs. We started to work on it for our own use but I believe something similar could be done that's more generic and could work with any hypervm(not just NuklaiVM).
We were able to get the most basic version of the SDK working. You can check it out at https://github.com/Nuklai/nuklai-js-sdk/tree/v0.1.0
The README should contain all the information you need to get started but we have also provided with some examples code that you can just run on your machine(all you need to do is change the RPC node URL and blockchain ID in these example files and just run like any other node.js file).
Anyways, this is what the SDK can do currently:
This is a good starting point as majority of the legwork has been done. Tricky part was supporting the key generation and dealing with low level packaging of bytes before submitting the transactions to the network.
What's next?
It would be amazing if we make this SDK a bit more generic that works with any type of hypervm out there(not just NuklaiVM) so other developers in the HyperSDK community could also use the SDK to interact with their own blockchain. And then, Nuklai SDK would be updated to use this generic hypervm sdk so most stuff would be abstracted away for us.
Feel free to try out the SDK with Nuklai testnet or maybe in your own custom subnet you've been building using hypersdk. Would love to hear feedback from others so we can improve it and work towards a common sdk that could be utilized by everyone.
To get started with Nuklai testnet, feel free to check out https://docs.nukl.ai/nuklai-network/nuklai-testnet/interact-with-testnet
Beta Was this translation helpful? Give feedback.
All reactions