For those not using any JS bundling/complilation or compilation technique or tools like Codepen or similar online Editors, please check our Import SDK bundle with <script>
tag.
If you're using bundling/compilation techniques (eg. webpack
), please continue reading.
Add the latest @aeternity/aepp-sdk
release from npmjs.com to your project using one of these commands
# install using npm...or yarn or pnpm
npm i @aeternity/aepp-sdk
Note: To install a Pre-Release (latest beta
or alpha
version) using on the latest Node version, you have to install the package appending the @next
tag reference, or even use the #
symbol and the Repo URL to install a version coming from a specific branch.
# install the @next version of the SDK
npm i @aeternity/aepp-sdk@next
# install the #develop version of the SDK
npm i https://github.com/aeternity/aepp-sdk-js#develop
Note : If you experience errors during the installation, you might need to install build tools for your OS.
Windows: Windows Build Tools
npm install -g windows-build-tools
Ubuntu / Debian: Build Essential
sudo apt-get update
sudo apt-get install build-essential
Mac: Download Xcode from AppStore, then run
xcode-select --install
You can do many more things now, but you'll probably have to start with:
Create an account using the 💻 CLI
import { Crypto } from '@aeternity/aepp-sdk/es'
const keypair = Crypto.generateKeyPair()
console.log(`Secret key: ${keypair.secretKey}`)
console.log(`Public key: ${keypair.publicKey}`)
To get yourself some AEs you can use the 🚰 Faucet Aepp. Just add your publicKey, and you'll immediately get some test tokens.
Import the right flavor. For this example with get the Universal
flavor, which contains all the features of the SDK:
// Import Flavor
import Ae from '@aeternity/aepp-sdk/es/ae/universal' // or other flavor
// Use Flavor
import Ae from '@aeternity/aepp-sdk/es/ae/universal' // or other flavor
import MemoryAccount from '@aeternity/aepp-sdk/es/account/memory' // or other flavor
import Node from '@aeternity/aepp-sdk/es/node' // or other flavor
import { AE_AMOUNT_FORMATS } from '@aeternity/aepp-sdk/es/utils/amount-formatter'
const NODE_URL = 'https://testnet.aeternity.io'
const COMPILER_URL = 'COMPILER_URL' // required for using Contract
const ACCOUNT = MemoryAccount({ keypair: { secretKey: 'A_PRIV_KEY', publicKey: 'A_PUB_ADDRESS' } })
(async function () {
const nodeInstance = await Node({ url: NODE_URL })
const sdkInstance = await Ae({
compilerUrl: COMPILER_URL,
nodes: [ { name: 'test-net', instance: nodeInstance } ],
accounts: [ ACCOUNT ]
})
await sdkInstance.height() // get top block height
console.log('Current Block Height:', height)
await sdkInstance.spend(1, 'ak_asd23dasdasda...', { denomination: AE_AMOUNT_FORMATS.AE }) // spend one AE
})()