Skip to content

Commit

Permalink
Release/v2.22.0 (#1492)
Browse files Browse the repository at this point in the history
* add new status codes (#1400)

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* Release/v2.20.0 beta.4 (#1431)

* added some supportability for hip-583

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* added deprecation of methods and some refactoring

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* remove unused aliasEvmAddress field

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* added creation of AccountId examples

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* AccountId examples refactoring

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* init hip583 examples

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* add examples and fix tx model

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* after lint

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* almost finalized the examples, getting data from mirror node works

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* new proto package version version

Signed-off-by: ochikov <ognyan@limechain.tech>

* use newer version for protobufs

Signed-off-by: ochikov <ognyan@limechain.tech>

* proto updates and examples enhancements

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* fixed build errors

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* update the proto package install task

Signed-off-by: ochikov <ognyan@limechain.tech>

* adjusted hip-583 examples

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* example updates and fixes

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* update examples and remove unnecessary step

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* add fromEvmPublicAddress() to AccountId

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* transfer using evm address enhancements

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* fixed all of the examples plus added 2 new status codes from services

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* New proto version

Signed-off-by: ochikov <ognyan@limechain.tech>

* make the sdk to use new proto version

Signed-off-by: ochikov <ognyan@limechain.tech>

* fixed proto files

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* remove status codes, need separate branch

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* add new status codes

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* fixed lint errors after task build

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* update pnpm lock files

Signed-off-by: ochikov <ognyan@limechain.tech>

* Update the package.json version

Signed-off-by: ochikov <ognyan@limechain.tech>

* Fix/timeout issue (#1414)

* add new status codes (#1400)

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* Fix the workflow for address book update and the workflow for timeout error processing

Signed-off-by: ochikov <ognyan@limechain.tech>

* Integration tests fixes with new account and logging of the failed address book query

Signed-off-by: ochikov <ognyan@limechain.tech>

* remove unused imports

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Signed-off-by: ochikov <ognyan@limechain.tech>
Co-authored-by: petreze <petar.tonev@limechain.tech>

* Update package.json

Signed-off-by: ochikov <ognyan@limechain.tech>

* Update package.json

Signed-off-by: ochikov <ognyan@limechain.tech>

* fix ping to throw (#1426)

Signed-off-by: ochikov <ognyan@limechain.tech>

* Bump up dependencies (#1402)

* add new status codes (#1400)

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* Bump up dependencies

Signed-off-by: ochikov <ognyan@limechain.tech>

* Cast the values so TS won't throw an error

Signed-off-by: ochikov <ognyan@limechain.tech>

* update package.json with new versions

Signed-off-by: ochikov <ognyan@limechain.tech>

* revert the grpc version update due to breaking changes

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Signed-off-by: ochikov <ognyan@limechain.tech>
Co-authored-by: petreze <petar.tonev@limechain.tech>

* removed unnecessary check

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* revert refactor

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* Removed unnecessary check (#1429)

* removed unnecessary check

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* Update package.json of cryptography

Signed-off-by: ochikov <ognyan@limechain.tech>

* update the cryptography package used in the sdk

Signed-off-by: ochikov <ognyan@limechain.tech>

* fix integration test for topic message query

Signed-off-by: ochikov <ognyan@limechain.tech>

* remove the only from the failing test

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Signed-off-by: ochikov <ognyan@limechain.tech>
Co-authored-by: ochikov <ognyan@limechain.tech>

* Fix inaccurate cost calculation (#1430)

* fix inaccurate cost calculation

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* rename misleading comment

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

---------

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* update the package version

Signed-off-by: ochikov <ognyan@limechain.tech>

* fix get cost and unit test

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Signed-off-by: ochikov <ognyan@limechain.tech>
Co-authored-by: Petar Tonev <petar.tonev@limechain.tech>

* chore(deps-dev): bump typescript in /examples/react-native-example (#1438)

Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.9.4 to 4.9.5.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](microsoft/TypeScript@v4.9.4...v4.9.5)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump react-native in /examples/react-native-example (#1437)

Bumps [react-native](https://github.com/facebook/react-native) from 0.71.1 to 0.71.2.
- [Release notes](https://github.com/facebook/react-native/releases)
- [Changelog](https://github.com/facebook/react-native/blob/main/CHANGELOG.md)
- [Commits](facebook/react-native@v0.71.1...v0.71.2)

---
updated-dependencies:
- dependency-name: react-native
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump react-native-web in /examples/react-native-example (#1436)

Bumps [react-native-web](https://github.com/necolas/react-native-web) from 0.18.10 to 0.18.12.
- [Release notes](https://github.com/necolas/react-native-web/releases)
- [Commits](necolas/react-native-web@0.18.10...0.18.12)

---
updated-dependencies:
- dependency-name: react-native-web
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump ua-parser-js in /examples/react-native-example (#1435)

Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.31 to 0.7.33.
- [Release notes](https://github.com/faisalman/ua-parser-js/releases)
- [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md)
- [Commits](faisalman/ua-parser-js@0.7.31...0.7.33)

---
updated-dependencies:
- dependency-name: ua-parser-js
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump decode-uri-component in /examples/react-native-example (#1434)

Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2.
- [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases)
- [Commits](SamVerschueren/decode-uri-component@v0.2.0...v0.2.2)

---
updated-dependencies:
- dependency-name: decode-uri-component
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* update axios

Signed-off-by: ochikov <ognyan@limechain.tech>

* update the playwright package

Signed-off-by: ochikov <ognyan@limechain.tech>

* Fix/update mirror endpoints (#1448)

* Fix _maxAutomaticTokenAssociations in contract create and contract up… (#1444)

* Fix _maxAutomaticTokenAssociations in contract create and contract update transactions

Signed-off-by: ochikov <ognyan@limechain.tech>

* set the fields default to null

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: ochikov <ognyan@limechain.tech>

* Update the mirror node endpoints

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: ochikov <ognyan@limechain.tech>

* Release/v2.20.0 (#1464)

* Fix _maxAutomaticTokenAssociations in contract create and contract up… (#1444)

* Fix _maxAutomaticTokenAssociations in contract create and contract update transactions

Signed-off-by: ochikov <ognyan@limechain.tech>

* set the fields default to null

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: ochikov <ognyan@limechain.tech>

* Feature/extend ethereumflow (#1447)

* init progress

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* Extend ethereum flow to accept maxChunks

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Signed-off-by: ochikov <ognyan@limechain.tech>
Co-authored-by: Petar Tonev <petar.tonev@limechain.tech>

* Add delete nft allowances and add delegate spender functionality (#1452)

* small refactoring

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* Fix/update mirror endpoints (#1448)

* Fix _maxAutomaticTokenAssociations in contract create and contract up… (#1444)

* Fix _maxAutomaticTokenAssociations in contract create and contract update transactions

Signed-off-by: ochikov <ognyan@limechain.tech>

* set the fields default to null

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: ochikov <ognyan@limechain.tech>

* Update the mirror node endpoints

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: ochikov <ognyan@limechain.tech>

* add missing functionalities from hip-336 nft allowances

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* small description typo

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

---------

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Signed-off-by: ochikov <ognyan@limechain.tech>
Co-authored-by: ochikov <ochikov@users.noreply.github.com>

* TokenWipe test twean and fix the version in package.json

Signed-off-by: ochikov <ognyan@limechain.tech>

* remove entirely hip-583 supportability

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* after build

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* new cryptography version

Signed-off-by: ochikov <ognyan@limechain.tech>

* used new crypto package version and update the last proto version

Signed-off-by: ochikov <ognyan@limechain.tech>

* new proto packages

Signed-off-by: ochikov <ognyan@limechain.tech>

* new packages versions

Signed-off-by: ochikov <ognyan@limechain.tech>

* release/2.20.0

Signed-off-by: ochikov <ognyan@limechain.tech>

* export fee assessment method

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

---------

Signed-off-by: ochikov <ognyan@limechain.tech>
Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Co-authored-by: Petar Tonev <petar.tonev@limechain.tech>

* Feature nft allowance tests (#1468)

* Fix _maxAutomaticTokenAssociations in contract create and contract up… (#1444)

* Fix _maxAutomaticTokenAssociations in contract create and contract update transactions

Signed-off-by: ochikov <ognyan@limechain.tech>

* set the fields default to null

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: ochikov <ognyan@limechain.tech>

* Feature/extend ethereumflow (#1447)

* init progress

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* Extend ethereum flow to accept maxChunks

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Signed-off-by: ochikov <ognyan@limechain.tech>
Co-authored-by: Petar Tonev <petar.tonev@limechain.tech>

* Add delete nft allowances and add delegate spender functionality (#1452)

* small refactoring

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* Fix/update mirror endpoints (#1448)

* Fix _maxAutomaticTokenAssociations in contract create and contract up… (#1444)

* Fix _maxAutomaticTokenAssociations in contract create and contract update transactions

Signed-off-by: ochikov <ognyan@limechain.tech>

* set the fields default to null

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: ochikov <ognyan@limechain.tech>

* Update the mirror node endpoints

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: ochikov <ognyan@limechain.tech>

* add missing functionalities from hip-336 nft allowances

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* small description typo

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

---------

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Signed-off-by: ochikov <ognyan@limechain.tech>
Co-authored-by: ochikov <ochikov@users.noreply.github.com>

* TokenWipe test twean and fix the version in package.json

Signed-off-by: ochikov <ognyan@limechain.tech>

* remove entirely hip-583 supportability

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* after build

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* new cryptography version

Signed-off-by: ochikov <ognyan@limechain.tech>

* used new crypto package version and update the last proto version

Signed-off-by: ochikov <ognyan@limechain.tech>

* new proto packages

Signed-off-by: ochikov <ognyan@limechain.tech>

* new packages versions

Signed-off-by: ochikov <ognyan@limechain.tech>

* release/2.20.0

Signed-off-by: ochikov <ognyan@limechain.tech>

* export fee assessment method

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* add tests and examples for add/remove nft allowances

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* separate nft allowance integration tests

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* update test description

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

---------

Signed-off-by: ochikov <ognyan@limechain.tech>
Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Co-authored-by: ochikov <ochikov@users.noreply.github.com>
Co-authored-by: ochikov <ognyan@limechain.tech>

* Release/hip 583 (#1472)

* init hip583

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* full support

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>

* fix example for nft allowances

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Signed-off-by: ochikov <ognyan@limechain.tech>
Co-authored-by: ochikov <ognyan@limechain.tech>

* update package.json

Signed-off-by: ochikov <ognyan@limechain.tech>

* release/v2.22.0

Signed-off-by: ochikov <ognyan@limechain.tech>

---------

Signed-off-by: Petar Tonev <petar.tonev@limechain.tech>
Signed-off-by: ochikov <ognyan@limechain.tech>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: petreze <petar.tonev@limechain.tech>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 7, 2023
1 parent e442263 commit bdebca9
Show file tree
Hide file tree
Showing 72 changed files with 8,984 additions and 4,958 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Default code owners for entire repository
* @danielakhterov @mehcode @SimiHunjan
* @SimiHunjan @ochikov @petreze
1,419 changes: 729 additions & 690 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/account-alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function main() {
);

/*
* Hedera supports a form of lazy account creation.
* Hedera supports a form of auto account creation.
*
* You can "create" an account by generating a private key, and then deriving the public key,
* without any need to interact with the Hedera network. The public key more or less acts as the user's
Expand Down
58 changes: 58 additions & 0 deletions examples/account-creation-ways.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { AccountId, PrivateKey } from "@hashgraph/sdk";

import dotenv from "dotenv";

dotenv.config();

function main() {
/* Source and context: https://hips.hedera.com/hip/hip-583
In hedera Hedera, we have the concept of 4 different account representations
- An account can have an account ID in shard.realm.accountNumber format (0.0.10)
- An account can have a public key alias in 0.0.CIQNOWUYAGBLCCVX2VF75U6JMQDTUDXBOLZ5VJRDEWXQEGTI64DVCGQ format
- An account can have an AccountId that is represented in 0x000000000000000000000000000000000000000a (for account ID 0.0.10) long zero format
- An account have be represented by an Ethereum public address 0xb794f5ea0ba39494ce839613fffba74279579268
*/

/*
Account ID - shard.realm.number format, i.e. `0.0.10` with the corresponding `0x000000000000000000000000000000000000000a` ethereum address
*/
const hederaFormat = AccountId.fromString("0.0.10");
console.log(`Account ID: ${hederaFormat.toString()}`);
console.log(
`Account 0.0.10 corresponding Long-Zero address: ${hederaFormat.toSolidityAddress()}`
);

/*
Hedera Long-Form Account ID - 0.0.aliasPublicKey, i.e. `0.0.CIQNOWUYAGBLCCVX2VF75U6JMQDTUDXBOLZ5VJRDEWXQEGTI64DVCGQ`
*/
const privateKey = PrivateKey.generateECDSA();
const publicKey = privateKey.publicKey;

// Assuming that the target shard and realm are known.
// For now they are virtually always 0 and 0.
const aliasAccountId = publicKey.toAccountId(0, 0);
console.log(`Hedera Long-Form Account ID: ${aliasAccountId.toString()}`);

/*
Hedera Account Long-Zero address - 0x000000000000000000000000000000000000000a (for accountId 0.0.10)
*/
const longZeroAddress = AccountId.fromString(
"0x000000000000000000000000000000000000000a"
);
console.log(
`Hedera Account Long-Zero address: ${longZeroAddress.toString()}`
);

/*
Ethereum Account Address / public-address - 0xb794f5ea0ba39494ce839613fffba74279579268
*/
const evmAddress = AccountId.fromString(
"0xb794f5ea0ba39494ce839613fffba74279579268"
);
console.log(
`Ethereum Account Address / public-address: ${evmAddress.toString()}`
);
}

void main();
3 changes: 1 addition & 2 deletions examples/create-stateful-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ async function main() {
.setGas(75000)
// Set the function to call on the contract
.setFunction("get_message")
// Set the query payment explicitly since sometimes automatic payment calculated
// is too low
// Set query payment explicitly
.setQueryPayment(new Hbar(3))
.executeWithSigner(wallet);

Expand Down
2 changes: 1 addition & 1 deletion examples/get-address-book.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function main() {

if (process.env.HEDERA_NETWORK.toLowerCase() === "mainnet") {
client
.setMirrorNetwork(["mainnet-public.mirrornode.hedera.com:5600"])
.setMirrorNetwork(["mainnet-public.mirrornode.hedera.com:443"])
.setTransportSecurity(true);
}

Expand Down
186 changes: 186 additions & 0 deletions examples/lazy-create-transfer-tx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import {
AccountId,
PrivateKey,
Client,
TransferTransaction,
AccountInfoQuery,
TransactionReceiptQuery,
TopicCreateTransaction,
} from "@hashgraph/sdk";

import dotenv from "dotenv";

dotenv.config();

/*
Lazy-create a new account using a public-address via a `TransferTransaction`.
Reference: [HIP-583 Expand alias support in CryptoCreate & CryptoTransfer Transactions](https://hips.hedera.com/hip/hip-583)
## Example 2
- Create an ECSDA private key
- Extract the ECDSA public key
- Extract the Ethereum public address
- Add function to calculate the Ethereum Address to in SDK
- Ethereum account address / public-address - This is the rightmost 20 bytes of the 32 byte Keccak-256 hash of the ECDSA public key of the account. This calculation is in the manner described by the Ethereum Yellow Paper.
- Use the `TransferTransaction`
- Populate the `FromAddress` with the sender Hedera AccountID
- Populate the `ToAddress` with Ethereum public address
- Note: Can transfer from public address to public address in the `TransferTransaction` for complete accounts. Transfers from hollow accounts will not work because the hollow account does not have a public key assigned to authorize transfers out of the account
- Sign the `TransferTransaction` transaction using an existing Hedera account and key paying for the transaction fee
- The `AccountCreateTransaction` is executed as a child transaction triggered by the `TransferTransaction`
- The Hedera Account that was created has a public address the user specified in the TransferTransaction ToAddress
- Will not have a public key at this stage
- Cannot do anything besides receive tokens or hbars
- The alias property of the account does not have the public address
- Referred to as a hollow account
- To get the new account ID ask for the child receipts or child records for the parent transaction ID of the `TransferTransaction`
- Get the `AccountInfo` and verify the account is a hollow account with the supplied public address (may need to verify with mirror node API)
- To enhance the hollow account to have a public key the hollow account needs to be specified as a transaction fee payer in a HAPI transaction
- Create a HAPI transaction and assign the new hollow account as the transaction fee payer
- Sign with the private key that corresponds to the public key on the hollow account
- Get the `AccountInfo` for the account and return the public key on the account to show it is a complete account
*/

async function main() {
if (process.env.OPERATOR_ID == null || process.env.OPERATOR_KEY == null) {
throw new Error(
"Environment variables OPERATOR_ID, and OPERATOR_KEY are required."
);
}
const operatorId = AccountId.fromString(process.env.OPERATOR_ID);
const operatorKey = PrivateKey.fromString(process.env.OPERATOR_KEY);

const client = Client.forTestnet().setOperator(operatorId, operatorKey);

/**
* Step 1
*
* Create an ECSDA private key
*/
const privateKey = PrivateKey.generateECDSA();
console.log(`Private key: ${privateKey.toStringDer()}`);

/**
* Step 2
*
* Extract the ECDSA public key
*/
const publicKey = privateKey.publicKey;
console.log(`Public key: ${publicKey.toStringDer()}`);

/**
*
* Step 3
*
* Extract the Ethereum public address
*/
const evmAddress = publicKey.toEvmAddress();
console.log(`New account ID: ${evmAddress}`);

/**
*
* Step 4
*
* Use the `TransferTransaction`
* - Populate the `FromAddress` with the sender Hedera AccountID
* - Populate the `ToAddress` with Ethereum public address
*/
const transferTx = new TransferTransaction()
.addHbarTransfer(operatorId, -10)
.addHbarTransfer(evmAddress, 10)
.freezeWith(client);

/**
*
* Step 5
*
* Sign the `TransferTransaction` transaction using an existing Hedera account and key paying for the transaction fee
*/
const transferTxSign = await transferTx.sign(operatorKey);
const transferTxSubmit = await transferTxSign.execute(client);

/**
*
* Step 6
*
* To get the new account ID ask for the child receipts or child records for the parent transaction ID of the `TransferTransaction`
* - The `AccountCreateTransaction` is executed as a child transaction triggered by the `TransferTransaction`
*/
const receipt = await new TransactionReceiptQuery()
.setTransactionId(transferTxSubmit.transactionId)
.setIncludeChildren(true)
.execute(client);

const newAccountId = receipt.children[0].accountId.toString();
console.log(`Account ID of the newly created account: ${newAccountId}`);

/**
*
* Step 7
*
* Get the `AccountInfo` and verify the account is a hollow account with the supplied public address
*
* The Hedera Account that was created has a public address the user specified in the TransferTransaction ToAddress
- Will not have a public key at this stage
- Cannot do anything besides receive tokens or hbars
- The alias property of the account does not have the public address
- Referred to as a hollow account
*/
const hollowAccountInfo = await new AccountInfoQuery()
.setAccountId(newAccountId)
.execute(client);

console.log(`Check if it is a hollow account with 'AccountInfoQuery'`);
hollowAccountInfo.aliasKey === null &&
hollowAccountInfo.key._toProtobufKey().keyList.keys.length == 0 &&
hollowAccountInfo.contractAccountId !== null
? console.log(`The newly created account is a hollow account`)
: console.log(`Not a hollow account`);

/**
*
* Step 8
*
* Create a HAPI transaction and assign the new hollow account as the transaction fee payer
* - To enhance the hollow account to have a public key the hollow account needs to be specified as a transaction fee payer in a HAPI transaction
*/

// set the accound id of the hollow account and its private key as an operator
// in order to be a transaction fee payer in a HAPI transaction
client.setOperator(newAccountId, privateKey);

let transaction = new TopicCreateTransaction()
.setTopicMemo("HIP-583")
.freezeWith(client);

/**
*
* Step 9
*
* Sign with the private key that corresponds to the public key on the hollow account
*/
const transactionSign = await transaction.sign(privateKey);
const transactionSubmit = await transactionSign.execute(client);
const status = (
await transactionSubmit.getReceipt(client)
).status.toString();
console.log(`HAPI transaction status: ${status}`);

/**
*
* Step 10
*
* Get the `AccountInfo` for the account and return the public key on the account to show it is a complete account
*/
const completeAccountInfo = await new AccountInfoQuery()
.setAccountId(newAccountId)
.execute(client);
completeAccountInfo.key !== null
? console.log(
`The public key of the newly created and now complete account: ${completeAccountInfo.key.toString()}`
)
: console.log(`Account ${newAccountId} is still a hollow account`);
}

void main();
Loading

0 comments on commit bdebca9

Please sign in to comment.