Skip to content

Commit

Permalink
fix(903): wrong init hedera client while associate tokens to account (#…
Browse files Browse the repository at this point in the history
…908)

Signed-off-by: Asen Prodanov <[email protected]>
  • Loading branch information
asenslime authored Aug 15, 2023
1 parent 3a6873d commit 08b8458
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions scripts/token/native/create/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
setSupplyKey := flag.Bool("setSupplyKey", true, "Sets supply key to be the deployer")

fmt.Println("-----------Start-----------")
client := client.Init(*privateKey, *accountID, *network)
cl := client.Init(*privateKey, *accountID, *network)

mirrorNodeConfigByNetwork := map[uint64]config.MirrorNode{
HederaMainnetNetworkId: {
Expand Down Expand Up @@ -99,8 +99,8 @@ func main() {
}

tokenId, err := create.CreateNativeFungibleToken(
client,
client.GetOperatorAccountID(),
cl,
cl.GetOperatorAccountID(),
*tokenName,
*tokenSymbol,
*decimals,
Expand All @@ -117,36 +117,37 @@ func main() {
panic(err)
}

receipt, err := associate.TokenToAccountWithCustodianKey(client, *tokenId, bridgeIDFromString, custodianKey)
receipt, err := associate.TokenToAccountWithCustodianKey(cl, *tokenId, bridgeIDFromString, custodianKey)
if err != nil {
panic(err)
}
fmt.Println("Token ID:", tokenId)
fmt.Println("Associate transaction status:", receipt.Status)

// associate token with members
for _, memberPrKey := range membersPublicKey {
accounts, err := mirrorNodeClient.GetAccountByPublicKey(memberPrKey.String())
for memberPubKeyIndex, memberPubKey := range membersPublicKey {
accounts, err := mirrorNodeClient.GetAccountByPublicKey(memberPubKey.String())
if err != nil {
panic(fmt.Errorf("cannot obtain account by public key: %w", err))
}

if len(accounts.Accounts) == 0 {
panic("cannot find account by public key")
} else if len(accounts.Accounts) != 1 {
panic("multiple accounts found for public key - " + memberPrKey.String())
panic("multiple accounts found for public key - " + memberPubKey.String())
}

hAccount, err := hedera.AccountIDFromString(accounts.Accounts[0].Account)
if err != nil {
panic(fmt.Errorf("cannot convert string to hedera account: %w", err))
}

receipt, err := associate.TokenToAccount(client, *tokenId, hAccount)
hClient := client.Init(membersSlice[memberPubKeyIndex], hAccount.String(), *network)
tokenToAccountReceipt, err := associate.TokenToAccount(hClient, *tokenId, hAccount)
if err != nil {
panic(fmt.Errorf("failed to associate token to account: %w", err))
}
fmt.Printf("Account[%s] associated with token[%s], tx status: %s\n",
hAccount.String(), tokenId.String(), receipt.Status)
hAccount.String(), tokenId.String(), tokenToAccountReceipt.Status)
}
}

0 comments on commit 08b8458

Please sign in to comment.