HomeCoinsAeternity (AE)Setting Up æternity Javascrip SDK | by Djongo | Nov, 2021

Setting Up æternity Javascrip SDK | by Djongo | Nov, 2021

- Advertisement -

Djongo

Hey everybody and welcome back to our scheduled programming. After covering the basics and the various Types and Functions, we’re going to be focusing on setting up the æternity javascript SDK.

Setting Up æternity Javascrip SDK | by Djongo | Nov, 2021

First thing you want to do is to make sure you have the latest version of the SDK installed. Then, get yourself an æternity account key par to get some Æ to use on the testnet. The easiest way to do this is to use the aeternity CLI.

Remember to never use any public tool from the internet to generate critical things, for example handling mainnet Æ or interacting with important contracts.

After installation, simply run “æcli account generate 2” and hit “y” to have two key pairs generated. Following this, you can head on over to æternity’s testnet faucet, enter the wallet address public key you just generated, and have five test Æ delivered to your accounts. (this may take a few seconds, that is as long as it takes for the block to get mined).

For a cool, informative video on the matter, check out this one right here:

For full code example, head on over here.

SDK supports flavors which allow you to reduce your bundle size. However, if you wish to keep things simple, just go for the universal flavor.

Now, you define your variables that hold your public and private keys. These are used to instantiate the so-called memory accounts inside the applications. These accounts live only in memory and will be used for blockchain operations. Once the SDK is set up you can, of course, add more accounts on the go, later on.

PSA Kind Reminder: Never hardcode private keys in the web app.

Ok, now back to it.

Defining an async function will allow the javascript to use away syntax. The SDK will need at least one node in order to be able to communicate with the æternity blockchain. This can be a private node, or any node for that matter, running on a network that your accounts have funds in. In the argument object of the SDK setup, you can provide an area of nodes to use.

The URL is supposed to point to a node for sending transactions and the internal URL for executing local smart contract code (which, theoretically, not all public nodes could allow). For the time being, you need to provide an URL to host a compiler which can either be the public one that æternity blockchain is running, or your own one which you can run locally on your machine in a docker container.

In accounts, you input the memory accounts you just defined, and address takes public key of the accounts you wish to use for any operations by default. To test your connection to the node just ask for the current block height.

Now, to test things, head over to Sophia IDE and copy your contract code (of course, you can use any example code). Create a template and just paste the code into it. Watch out however — IDEs tend to, from time to time, tamper with code indentations. To test this, just hit “undo” after pasting and you will be able to see if your code has been tampered with.

Next, you create a contract instance with the help of the SDK by acting as if you were executing your smart contracts init function. Actually, you send a transaction to deploy the corresponding smart contract to the æternity blockchain. This, implicitly, runs its init function with the parameters you pass. It is worth, though, locking the contract instance and see what useful information it has to offer about the contract you just deployed.

For the final step — let’s call it! Go ahead and create a try catch clause. For every function you define in your contract you have a member function inside your contracts instances methods member. Awesome feature here is that the SDK knows exactly which function just reads the data from your smart contract and which changes the state, and therefore requires a transaction to be done. If you wish to play things safe, you can explicitly state the behavior of every function call. Now, pass your parameters neatly formatted.

You can dry-run stateful functions for testing and overall curiosity! This will help you find out if they will be executed properly at that very moment.

If you wish to choose which of the previously added accounts, pass an option object to your call. You can also, while here, define the amount of ætos — the smallest subunit of Æ — to be sent along with your transaction. The same is possible for contracts deployment too! Just check the SDK for more neat tricks you can do in the options.

For more details and an in depth look into all of the material covered above, again, check out æeternity’s very own Nikita’s awesome video covering the topic! There, you have a step-by-step how-to on all of these points.

Let me know in the comments how you like this guide! All suggestions welcome!

Of course, further discussions on the aeternity forum as well as the telegram group are more than appreciated! And, don’t forget, æternity has an entire playlist on YouTube dedicated to Sophia!

And, check these out too:

Full code example: https://github.com/nikita-fuchs/video…

AE testnet faucet: https://faucet.aepps.com/

SDK: https://www.npmjs.com/package/@aetern…

Aeternity CLI: https://www.npmjs.com/package/@aetern…

Read the original article here

- Advertisement -
Mr Bitcointehttps://www.bitcointe.com/
“Fact You Need To Know About Cryptocurrency - The first Bitcoin purchase was for pizza.” ― Mohsin Jameel
462FansLike
76FollowersFollow
4,567FollowersFollow
5,261FollowersFollow
1,547FollowersFollow
2,230SubscribersSubscribe

Most Popular

bitcoin
Bitcoin (BTC) $ 56,866.00
ethereum
Ethereum (ETH) $ 4,583.56
tether
Tether (USDT) $ 1.00
bitcoin-cash
Bitcoin Cash (BCH) $ 559.41
litecoin
Litecoin (LTC) $ 203.97
eos
EOS (EOS) $ 4.05
okb
OKB (OKB) $ 29.21
tezos
Tezos (XTZ) $ 5.14
leo-token
LEO Token (LEO) $ 3.55
cardano
Cardano (ADA) $ 1.66
monero
Monero (XMR) $ 242.52
stellar
Stellar (XLM) $ 0.351601
chainlink
Chainlink (LINK) $ 25.17
huobi-token
Huobi Token (HT) $ 9.66
tron
TRON (TRX) $ 0.100181
usd-coin
USD Coin (USDC) $ 1.00
dash
Dash (DASH) $ 178.71
neo
NEO (NEO) $ 37.27
iota
IOTA (MIOTA) $ 1.48
nem
NEM (XEM) $ 0.169663
zcash
Zcash (ZEC) $ 224.50
maker
Maker (MKR) $ 2,927.30
paxos-standard
Pax Dollar (USDP) $ 0.995795
ethereum-classic
Ethereum Classic (ETC) $ 47.38
vechain
VeChain (VET) $ 0.116118
true-usd
TrueUSD (TUSD) $ 1.00
ftx-token
FTX Token (FTT) $ 49.33
kucoin-shares
KuCoin Token (KCS) $ 25.78
waves
Waves (WAVES) $ 20.99