In case you're not using any JS bundling/compilation technique, the SDK can also be loaded with the traditional <script>
tag, as follows:
<script src="https://unpkg.com/@aeternity/aepp-sdk/dist/aepp-sdk.browser-script.cjs"></script>
<script src="https://unpkg.com/@aeternity/aepp-sdk@VERSION/dist/aepp-sdk.browser-script.cjs"></script>
...where VERSION
is the version number of the SDK you want to use (eg. 14.0.0
).
The bundle will assign the SDK to a global variable called Aeternity
that makes all functionalities of the SDK accessible.
Usage:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<!-- include latest SDK version -->
<script src="https://unpkg.com/@aeternity/aepp-sdk/dist/aepp-sdk.browser-script.cjs"></script>
<script type="text/javascript">
const { AeSdk, Node } = Aeternity;
const node = new Node('https://testnet.aeternity.io');
const aeSdk = new AeSdk({
nodes: [{ name: 'testnet', instance: node }],
});
aeSdk.getHeight().then((height) => {
console.log('Current Block Height:' + height);
});
</script>
</body>
</html>
npm i @aeternity/aepp-sdk
To install a Pre-Release (latest beta
or alpha
version) you have to install the package appending the @next
tag reference.
npm i @aeternity/aepp-sdk@next
You can also install a version coming from a specific branch. In this case you would install the SDK version of the develop
branch.
npm i github:aeternity/aepp-sdk-js#develop
To work properly, sdk requires to enable allowSyntheticDefaultImports
flag and register folder
that contains type definitions for third-party packages sdk depends on.
This may be done in tsconfig.json
:
{
"compilerOptions": {
...
+ "typeRoots": [
+ "node_modules/@types",
+ "node_modules/@aeternity/aepp-sdk/src/typings"
+ ],
+ "allowSyntheticDefaultImports": true
}
}
Ensure that you have strictFunctionTypes
option not enabled (as it is in VS code and ts-node
by default), otherwise some of SDK types won't work correctly (see #1793).
In some environments, TypeScript fails to check types of sdk's dependencies (@metamask/json-rpc-engine
, @ledgerhq/hw-transport
), if so you may find skipLibCheck
useful.
SDK checks are not working correctly because CLI picks both ESM and CJS versions of autorest
dependencies. To fix this, you need to specify aliases in vue.config.js
.
module.exports = {
configureWebpack: {
resolve: {
alias: {
+ '@azure/core-client': '@azure/core-client/dist-esm/src/index.js',
+ '@azure/core-rest-pipeline': '@azure/core-rest-pipeline/dist-esm/src/index.js',
},
},
},
};
Reactivity in Vue@3 based on Proxy class. Proxy is not compatible with private fields of ES classes. AeSdk, Contract and MemoryAccount classes uses private fields, so if you make an instance of these classes reactive then the app may fail with
TypeError: attempted to get private field on non-instance
AeSdk and Contract classes doesn’t have a state intended to be tracked using reactivity. Therefore to solve this issue we suggest to avoid making their instances reactive using Vue's integrated utility: shallowRef. The idea is to make reactive only the instance value, to don't make it reactive in deep.
Alternatively, toRaw can unwrap the proxy object, returning an unmodified instance and allowing access to its private properties by its methods. It can be useful if you need a reactive array of MemoryAccount.
You can find both approaches used in the æpp example.
If you don't need to include specific functionality into your application and just want to use or play around with features the SDK provides you can make use of the 💻 CLI and follow the instructions mentioned there.