I’ve done the following steps 1 through 3, and figuring out how to complete step 4.
(1) Generate several several EVM addresses (evmAddress*
) locally, and those EVM addresses do not have accounts on the Hedera network yet.
(2) Create a TransferTransaction
which transfers from an existing account (operatorId
) to the EVM addresses, like so:
const tinyBarsPerHbar = 100_000_000;
const multiTransferTx = new TransferTransaction()
.addHbarTransfer(operatorId, -30 * tinyBarsPerHbar)
.addHbarTransfer(evmAddress1, 10 * tinyBarsPerHbar)
.addHbarTransfer(evmAddress2, 10 * tinyBarsPerHbar)
.addHbarTransfer(evmAddress3, 10 * tinyBarsPerHbar)
.freezeWith(client)
.sign(operatorKey);
const transferTxResponse = await multiTransferTx.execute(client);
(3) When multiTransferTx
completes, the EVM addresses now have accounts on the Hedera network lazily created, and associated with them
(4) Now need to find out what account ID each EVM address maps to, i.e. produce something like this:
{
evmAddress1: accountId1,
evmAddress2: accountId2,
evmAddress3: accountId3,
}
How can step 4 be accomplished?
Note:
I have self-answered below, with a caveat that unfortunately makes it a not-good-enough solution. Would like to receive another answer that isn’t subject to this caveat where the order/ mapping is guaranteed.
2
Answers
Step 4 can be accomplished, with a caveat, described below, using the following code
This produces an output similar to this:
Subsequently, filtering this list by
amount === 1000000000
, yields the account IDs that I want.The caveat:
The above approach works, however, it does not state which account IDs map to which EVM addresses. We can make the assumption that the order in which these account IDs appear is the same as the order in which
addHbarTransfer
is called when creating themultiTransferTx
. And manual testing seems to bear this out - the order does indeed match. However, this is not documented behaviour, and thus is not guaranteed. We don't even know if the order is deterministic.You can query the account id of the accounts created by following these step:
Get the tx record:
const transferToAliasRec = await transferToAliasSubmit.getRecord(client);
Perform a record query with
.setIncludeChildren()
set totrue
:const txRec = await new TransactionRecordQuery().setTransactionId(transferToAliasRec.transactionId).setIncludeChildren(true).execute(client);
Iterate through the children with
i
to get the account id from the receipt from each child tx:[Optional] Double check on HashScan