Skip to content

Commit

Permalink
Merge pull request #1902 from aeternity/release/13.2.2
Browse files Browse the repository at this point in the history
Release 13.2.2
  • Loading branch information
davidyuk authored Sep 21, 2023
2 parents 5df22dd + 86c6f61 commit 7126ad0
Show file tree
Hide file tree
Showing 48 changed files with 514 additions and 332 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
node:
image: aeternity/aeternity:v6.8.1
image: aeternity/aeternity:v6.11.0
hostname: node
ports: ["3013:3013", "3113:3113", "3014:3014", "3114:3114"]
volumes:
Expand Down
2 changes: 1 addition & 1 deletion docker/aeternity_node_mean16.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ chain:
persist: false
hard_forks:
"1": 0
"6": 1
"5": 1

mining:
autostart: true
Expand Down
17 changes: 16 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [13.2.2](https://github.com/aeternity/aepp-sdk-js/compare/v13.2.1...v13.2.2) (2023-09-20)


### Bug Fixes

* use proper vm version in Ceres ([bcaa5cf](https://github.com/aeternity/aepp-sdk-js/commit/bcaa5cfe0f8a23a641d9db993b312e2d54cfdd60))
* **aepp,wallet:** connect to web-extension if opened over file:/// ([da6a025](https://github.com/aeternity/aepp-sdk-js/commit/da6a0257e995db38e32888390961eb870a482777))
* **aepp:** use complete type of WalletInfo object ([eeba565](https://github.com/aeternity/aepp-sdk-js/commit/eeba56576b97afda6739fa8cd0f9e5c6f039651f))
* **contract:** don't mark contract as deployed if tx failed ([cc4222d](https://github.com/aeternity/aepp-sdk-js/commit/cc4222db8dc979c878e6e51bea9634484b826de7))
* **contract:** use current nonce in static calls ([758bdfc](https://github.com/aeternity/aepp-sdk-js/commit/758bdfc75a1dd8e4ff0646ddeaa10e19b1a4d5d1))
* **node:** don't retry 500 code responses ([696e7db](https://github.com/aeternity/aepp-sdk-js/commit/696e7db88605a385789d741f2704aba2c1cee972))
* **node:** throw clear error message if unsupported protocol ([21dfe34](https://github.com/aeternity/aepp-sdk-js/commit/21dfe34b3645d95b4c54d99e8517a33634b3751f))
* **node:** uncatchable exception if request failed in queue ([dec62a4](https://github.com/aeternity/aepp-sdk-js/commit/dec62a474cad4639b81cbef46ff606c384f7ab53))
* typos in error messages and docs ([5c84671](https://github.com/aeternity/aepp-sdk-js/commit/5c846712a32a110e1a5df25d5c4366046d9558f5))

### [13.2.1](https://github.com/aeternity/aepp-sdk-js/compare/v13.2.0...v13.2.1) (2023-07-28)


Expand Down Expand Up @@ -48,7 +63,7 @@ All notable changes to this project will be documented in this file. See [standa
* **contract:** use fallback account if `onAccount` not provided ([9033cd7](https://github.com/aeternity/aepp-sdk-js/commit/9033cd799be5974ebf28a49df181eeb63b1fce84))
* converting proxied options to JSON ([efebbd1](https://github.com/aeternity/aepp-sdk-js/commit/efebbd139ea85c35e28bdcfe907670743f9fc1f4))
* provide types in exports field of package.json ([dbd19e7](https://github.com/aeternity/aepp-sdk-js/commit/dbd19e70bca2d6dbc5b2392db478bb98936b63f2))
* reject prefixes other then provided in isAddressValid ([9462add](https://github.com/aeternity/aepp-sdk-js/commit/9462adde8fab9848fca0a6d9a382dbd34f5e2b8f))
* reject prefixes other than provided in isAddressValid ([9462add](https://github.com/aeternity/aepp-sdk-js/commit/9462adde8fab9848fca0a6d9a382dbd34f5e2b8f))
* **tx-builder:** `buildTx` produces the same type as `unpackTx` accepts ([d3d6c88](https://github.com/aeternity/aepp-sdk-js/commit/d3d6c88607abbfb74acf016fba886540938b216d))
* **tx-builder:** decode tag in entry error message ([db0d96f](https://github.com/aeternity/aepp-sdk-js/commit/db0d96f156f3e8cfe52c6a7d7411c359f6dae35c))
* **wallet:** emit internal error if something broke while broadcast ([332d1b5](https://github.com/aeternity/aepp-sdk-js/commit/332d1b567f69bf6b7d3567af43fb805556ac015b))
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/address-length.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ Running the above code you would get output like
Therefore the minimum address length is 41 chars. All these addresses valid, for example
`ak_11111111111111111111111111111111273Yts` [used] to collect AENS name fees.
[isAddressValid]: https://docs.aeternity.com/aepp-sdk-js/v13.1.0/api/functions/isAddressValid.html
[isAddressValid]: https://docs.aeternity.com/aepp-sdk-js/v13.2.2/api/functions/isAddressValid.html
[used]: https://mainnet.aeternity.io/v3/accounts/ak_11111111111111111111111111111111273Yts
82 changes: 47 additions & 35 deletions docs/guides/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@ The smart contract language of the æternity blockchain is [Sophia](https://docs

Before interacting with contracts using the SDK you should get familiar with Sophia itself first. Have a look into [aepp-sophia-examples](https://github.com/aeternity/aepp-sophia-examples) and start rapid prototyping using [AEstudio](https://studio.aepps.com).

The SDK needs to interact with following components in order to enable smart contract interactions on the æternity blockchain:

- [æternity](https://github.com/aeternity/aeternity) (host your own one or use the public testnet node at `https://testnet.aeternity.io`)
- [aesophia_http](https://github.com/aeternity/aesophia_http) (host your own one or use the public compiler at `https://v7.compiler.aepps.com`)

Note:

- For production deployments you should ***always*** host these services by yourself.

## 1. Specify imports
```js
// node.js import
const { AeSdk, MemoryAccount, Node, CompilerHttp } = require('@aeternity/aepp-sdk')
const { AeSdk, MemoryAccount, Node } = require('@aeternity/aepp-sdk')
// ES import
import { AeSdk, MemoryAccount, Node, CompilerHttp } from '@aeternity/aepp-sdk'
import { AeSdk, MemoryAccount, Node } from '@aeternity/aepp-sdk'
// additionally you may need to import CompilerCli or CompilerHttp
```

## 2. Setup compiler
Compiler primarily used to generate bytecode to deploy a contract.
Skip this step if you have a contract bytecode or need to interact with an already deployed contract.
Out-of-the-box SDK supports [aesophia_cli](https://github.com/aeternity/aesophia_cli) and [aesophia_http](https://github.com/aeternity/aesophia_http) implemented in [CompilerCli](https://docs.aeternity.com/aepp-sdk-js/v13.2.2/api/classes/CompilerCli.html) and [CompilerHttp](https://docs.aeternity.com/aepp-sdk-js/v13.2.2/api/classes/CompilerHttp.html) respectively.

CompilerCli is available only in Node.js and requires Erlang installed (`escript` available in `$PATH`), Windows is supported.
```js
const compiler = new CompilerCli()
```

## 2. Create an instance of the SDK
CompilerHttp requires a hosted compiler service. Preferable to host your own compiler service since [compiler.aepps.com](https://v7.compiler.aepps.com/api) is planned to be decommissioned. An example of how to run it using [docker-compose](https://github.com/aeternity/aepp-sdk-js/blob/cd8dd7f76a6323383349b48400af0d69c2cfd88e/docker-compose.yml#L11-L14).
```js
const compiler = new CompilerHttp('https://v7.compiler.aepps.com') // host your own compiler
```

Both compiler classes implement the [same interface](https://docs.aeternity.com/aepp-sdk-js/v13.2.2/api/classes/CompilerBase.html) that can be used to generate bytecode and ACI without a Contract instance.

## 3. Create an instance of the SDK
When creating an instance of the SDK you need to provide an account which will be used to sign transactions like `ContractCreateTx` and `ContractCallTx` that will be broadcasted to the network.

```js
Expand All @@ -32,7 +41,7 @@ const account = new MemoryAccount(SECRET_KEY)
const aeSdk = new AeSdk({
nodes: [{ name: 'testnet', instance: node }],
accounts: [account],
onCompiler: new CompilerHttp('https://v7.compiler.aepps.com'), // ideally host your own compiler
onCompiler: compiler, // remove if step #2 skipped
})
```

Expand All @@ -42,7 +51,7 @@ Note:
- For each transaction you can choose a specific account to use for signing (by default the first account will be used), see [transaction options](../transaction-options.md).
- This is specifically important and useful for writing tests.

## 3. Initialize the contract instance
## 4. Initialize the contract instance

### By source code

Expand All @@ -59,6 +68,13 @@ Note:
const contract = await aeSdk.initializeContract({ sourceCode, fileSystem })
```

### By path to source code (available only in Node.js)
It can be used with both CompilerCli and CompilerHttp. This way contract imports would be handled automatically, with no need to provide `fileSystem` option.
```js
const sourceCodePath = './example.aes'
const contract = await aeSdk.initializeContract({ sourceCodePath })
```

### By ACI and bytecode
If you pre-compiled the contracts you can also initialize a contract instance by providing ACI and bytecode:

Expand All @@ -80,7 +96,7 @@ const contract = await aeSdk.initializeContract({ aci, address })
### Options

- Following attributes can be provided via `options` to `initializeContract`:
- `aci` (default: obtained via http compiler)
- `aci` (default: obtained via `onCompiler`)
- The Contract ACI.
- `address`
- The address where the contract is located at.
Expand All @@ -94,7 +110,11 @@ const contract = await aeSdk.initializeContract({ aci, address })
- You wouldn't want to provide an `amount` to each transaction or use the same `nonce` which would result in invalid transactions.
- For options like `ttl` or `gasPrice` it does absolutely make sense to set this on contract instance level.

## 4. Deploy the contract
### Keep bytecode and ACI for future use
After the contract is initialized you can persist values of `contract._aci` and `contract.$options.bytecode`.
They can be provided for subsequent contract initializations to don't depend on a compiler.
## 5. Deploy the contract
If you have a Sophia contract source code that looks like this:
```sophia
Expand Down Expand Up @@ -131,7 +151,7 @@ Note:
- In Sophia all `public functions` are called `entrypoints` and need to be declared as `stateful`
if they should produce changes to the state of the smart contract, see `increment(value: int)`.
## 5. Call contract entrypoints
## 6. Call contract entrypoints
### a) Stateful entrypoints
According to the example above you can call the `stateful` entrypoint `increment` by using one of the following lines:
Expand Down Expand Up @@ -187,21 +207,13 @@ const tx = await contract.$call('fund_project', [1], { amount: 50 })
As already stated various times in the guide it is possible to provide [transaction options](../transaction-options.md) as object to a function of the SDK that builds and potentially broadcasts a transaction. This object can be passed as additional param to each of these functions and overrides the default settings.

## Sophia datatype cheatsheet
Sometimes you might wonder how to pass params to the JavaScript method that calls an entrypoint of your Sophia smart contract. The following table may help you out.

| Type | Sophia entrypoint definition | JavaScript method call |
|-----------|-----------------------------------|--------------------------------------------------|
| int | `add_two(one: int, two: int)` | `add_two(1 , 2)` |
| address | `set_owner(owner: address)` | `set_owner('ak_1337...')` |
| bool | `is_it_true(answer: bool)` | `is_it_true(true)` |
| bits | `give_me_bits(input: bits)` | `give_me_bits(0b10110n)` |
| bytes | `get_bytes(test: bytes(3))` | `get_bytes(new Uint8Array([0x1, 0x1f, 0x10]))` |
| string | `hello_world(say_hello: string)` | `hello_world('Hello!')` |
| list | `have_a_few(candy: list(string))` | `have_a_few(['Skittles', 'M&Ms', 'JellyBelly'])` |
| tuple | `a_few_things(things: (string * int * map(address, bool)))` | `a_few_things(['hola', 3, new Map([['ak_1337...', true]])])` |
| record | `record user = {`<br />&nbsp; &nbsp; &nbsp; &nbsp; `firstname: string,` <br /> &nbsp; &nbsp; &nbsp; &nbsp; `lastname: string` <br /> `}` <br /> <br /> `get_firstname(input: user): string` | `get_firstname({'firstname': 'Alfred', 'lastname': 'Mustermann'})` |
| map | `balances(values: map(address, int))` | `balances(new Map([['ak_1337...', 123], ['ak_FCKGW...', 321], ['ak_Rm5U...', 999]]))` |
| option() | `number_defined(value: option(int)): bool = `<br /> &nbsp; &nbsp; &nbsp; &nbsp; `Option.is_some(value)` | `// the datatype in the option()` <br /> `number_defined(1337) // int in this case` |
| hash | `a_gram(of: hash)` | `// 32 bytes signature` <br /> `a_gram('af01...490f')` |
| signature | `one_signature(sig: signature)` | `// 64 bytes signature` <br /> `one_signature('af01...490f')` |
| functions | (Higher order) functions are not allowed in `entrypoint` params | |
Sometimes you might wonder how to pass params to the JavaScript method that calls an entrypoint of your Sophia smart contract.
The conversion between JS and Sophia values is handled by aepp-calldata library.
Refer to [its documentation](https://www.npmjs.com/package/@aeternity/aepp-calldata#data-types) to find the right type to use.

## Generate file system object in Node.js
To do so you can use [getFileSystem](https://docs.aeternity.com/aepp-sdk-js/v13.2.2/api/functions/getFileSystem.html) function.
In most cases, you don't need to do it explicitly. Prefer to use `sourceCodePath` instead `sourceCode` in
[Contract::initialize](https://docs.aeternity.com/aepp-sdk-js/v13.2.2/api/classes/_internal_.Contract.html#initialize),
and [compile](https://docs.aeternity.com/aepp-sdk-js/v13.2.2/api/classes/CompilerBase.html#compile)
instead [compileBySourceCode](https://docs.aeternity.com/aepp-sdk-js/v13.2.2/api/classes/CompilerBase.html#compileBySourceCode) in CompilerBase.
4 changes: 2 additions & 2 deletions docs/guides/paying-for-tx.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ You can then collect the signed inner transaction, wrap it into a `PayingForTx`
## Usage examples
We provided following two NodeJS examples which you can take a look at:

- [InnerTx: ContractCallTx](https://docs.aeternity.com/aepp-sdk-js/v13.1.0/examples/node/paying-for-contract-call-tx/)
- [InnerTx: SpendTx](https://docs.aeternity.com/aepp-sdk-js/v13.1.0/examples/node/paying-for-spend-tx/)
- [InnerTx: ContractCallTx](https://docs.aeternity.com/aepp-sdk-js/v13.2.2/examples/node/paying-for-contract-call-tx/)
- [InnerTx: SpendTx](https://docs.aeternity.com/aepp-sdk-js/v13.2.2/examples/node/paying-for-spend-tx/)

Note:

Expand Down
4 changes: 1 addition & 3 deletions docs/guides/typed-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ corresponds to the data

## Implementation

- [encodeFateValue](https://github.com/aeternity/aepp-sdk-js/blob/5952a7b9f4d0cf30ad7caa0831dfb974d1e91afc/src/utils/typed-data.ts#L44-L52) — use to generate the first argument for `signTypedData`;
- [AccountBase::signTypedData](https://github.com/aeternity/aepp-sdk-js/blob/5952a7b9f4d0cf30ad7caa0831dfb974d1e91afc/src/account/Base.ts#L63-L70) — calculates signature, supported in MemoryAccount and in aepp-wallet connection;
- [AccountBase:signTypedData](https://github.com/aeternity/aepp-sdk-js/blob/5952a7b9f4d0cf30ad7caa0831dfb974d1e91afc/src/account/Base.ts#L63-L70) — calculates signature, supported in MemoryAccount and in aepp-wallet connection;
- [hashTypedData](https://github.com/aeternity/aepp-sdk-js/blob/5952a7b9f4d0cf30ad7caa0831dfb974d1e91afc/src/utils/typed-data.ts#L87-L95) — calculates the overall hash of typed data to sign;
- [decodeFateValue](https://github.com/aeternity/aepp-sdk-js/blob/5952a7b9f4d0cf30ad7caa0831dfb974d1e91afc/src/utils/typed-data.ts#L55-L63) — use to preview data to sign on wallet side;
- [hashJson](https://github.com/aeternity/aepp-sdk-js/blob/5952a7b9f4d0cf30ad7caa0831dfb974d1e91afc/src/utils/typed-data.ts#L16-L18) — deterministic hashing of an arbitrary JS value, used to calculate `hash(aci)`;
- [hashDomain](https://github.com/aeternity/aepp-sdk-js/blob/5952a7b9f4d0cf30ad7caa0831dfb974d1e91afc/src/utils/typed-data.ts#L68-L85) — use for debugging or to prepare the hash value for smart contract.

Expand Down
3 changes: 2 additions & 1 deletion docs/quick-start.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Quick Start
In this example we will send 1 _AE_ coin from one account to another
In this example we will send 1 _AE_ coin from one account to another.
For more specific information on setups with Frameworks and TypeScript, please refer to the [installation instructions](./README.md).

## 1. Specify imports
For the following snippets in the guide you need to specify multiple imports.
Expand Down
15 changes: 8 additions & 7 deletions examples/browser/aepp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
"build": "vue-cli-service build"
},
"dependencies": {
"@aeternity/aepp-calldata": "^1.5.1",
"@aeternity/aepp-sdk": "file:../../..",
"buffer": "^6.0.3",
"core-js": "^3.22.6",
"core-js": "^3.32.1",
"tailwindcss": "^2.2.19",
"vue": "^3.2.36",
"vuex": "^4.0.2"
"vue": "^3.3.4",
"vuex": "^4.1.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~5.0.4",
"@vue/cli-service": "~5.0.4",
"sass": "^1.52.1",
"sass-loader": "^13.0.0"
"@vue/cli-plugin-babel": "~5.0.8",
"@vue/cli-service": "~5.0.8",
"sass": "^1.66.1",
"sass-loader": "^13.3.2"
},
"browserslist": [
"> 1%",
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/aepp/src/Connect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default {
walletConnected: false,
walletConnecting: null,
reverseIframe: null,
reverseIframeWalletUrl: process.env.VUE_APP_WALLET_URL ?? 'http://localhost:9000',
reverseIframeWalletUrl: process.env.VUE_APP_WALLET_URL ?? `http://${location.hostname}:9000`,
walletInfo: null,
cancelWalletDetection: null,
}),
Expand Down
Loading

0 comments on commit 7126ad0

Please sign in to comment.