⚡ Examples
This folder contains examples of maintained code samples that you can run autonomously.
VueJS (maintained) Examples to run in the browser
NodeJS (maintained and tested) Examples to run in the terminal
Quick Standalone Browser Example
This example interacts with aeternity's blockchain's Universal flavor (all SDK's functionalities, in the Browser)
// Start the instance using Universal flavor
import Ae from '@aeternity/aepp-sdk/es/ae/universal'
import Node from '@aeternity/aepp-sdk/es/node'
// const node1 = await Node({ url })
Ae({
nodes: [
// { name: 'someNode', instance: node1 },
// node2
],
compilerUrl: 'https://compiler.aepps.com',
accounts: [
MemoryAccount({ keypair: { secretKey: 'A_PRIV_KEY', publicKey: 'A_PUB_ADDRESS' } }),
// acc2
],
address: 'SELECTED_ACCOUNT_PUB',
networkId: 'ae_uat' // or any other networkId your client should connect to
}).then(ae => {
// Interacting with the blockchain client
// getting the latest block height
ae.height().then(height => {
// logs current height
console.log('height', height)
}).catch(e => {
// logs error
console.log(e)
})
// getting the balance of a public address
ae.balance('A_PUB_ADDRESS').then(balance => {
// logs current balance of "A_PUB_ADDRESS"
console.log('balance', balance)
}).catch(e => {
// logs error
console.log(e)
})
})
Quick Browser Examples for:
1. Wallet Example (only Wallet's functionalities)
interact with aeternity's blockchain's Wallet flavor – For Wallet development You can find a more complete example using VueJS here
// Start the instance using Wallet flavor
import Wallet from '@aeternity/aepp-sdk/es/ae/wallet'
const walletBalance
// Simple function to Guard SDK actions
const confirmDialog = function (method, params, {id}) {
return Promise.resolve(window.confirm(`User ${id} wants to run ${method} ${params}`))
}
Wallet({
nodes: [
// { name: 'someNode', instance: node1 },
// mode2
],
compilerUrl: 'https://compiler.aepps.com',
accounts: [
MemoryAccount({
keypair: {
secretKey: 'secr3tKeYh3RE',
publicKey: 'ak_pUbL1cH4sHHer3'
}
})
],
address: 'ak_pUbL1cH4sHHer3',
onTx: confirmDialog,
onChain: confirmDialog,
onAccount: confirmDialog,
onContract: confirmDialog,
networkId: 'ae_uat' // or any other networkId your client should connect to
}).then(ae => {
// Interact with the blockchain!
ae.balance(this.pub).then(balance => {
walletBalance = balance
}).catch(e => {
walletBalance = 0
})
})
2. Aepp Example (Aepp <--> Wallet via RPC)
interact with aeternity's blockchain's Aepp flavor – For Aepps development AKA DApp development You can find a more complete example using VueJS here
// Start the instance using Aepp flavor
import Aepp from '@aeternity/aepp-sdk/es/ae/aepp'
const pubKey
// Here, we're not initialising anything, assuming that this is an Aepp (DApp)
// working inside an Iframe of a "Wallet flavored" JS App
Aepp().then(ae => {
// Interact with the blockchain!
ae.address()
.then(address => {
//get address of the Wallet used by this Aepp
pubKey = address
})
.catch(e => { console.log(`Rejected: ${e}`) })
})