Skip to content

Commit

Permalink
added function to add leading zero
Browse files Browse the repository at this point in the history
  • Loading branch information
RuneRogue authored Aug 27, 2024
1 parent e7ef219 commit 16fd982
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion examples/deployAccount/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"strconv"
"strings"

"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/account"
Expand Down Expand Up @@ -32,6 +33,18 @@ var (
// Returns:
//
// none
// padAddress pads the given address with leading zeros to ensure it's 66 characters long
func padAddress(address string) string {
// Remove the "0x" prefix if it exists
if strings.HasPrefix(address, "0x") {
address = address[2:]
}
// Pad the address to ensure the total length is 64 characters (not including "0x")
address = strings.Repeat("0", 64-len(address)) + address
// Add the "0x" prefix back
return "0x" + address
}

func main() {
// Load variables from '.env' file
rpcProviderUrl := setup.GetRpcProviderUrl()
Expand Down Expand Up @@ -77,7 +90,17 @@ func main() {
if err != nil {
panic(err)
}
fmt.Println("PrecomputedAddress:", precomputedAddress)

// Pad the precomputed address
paddedAddress := padAddress(precomputedAddress.String())
fmt.Println("PrecomputedAddress:", paddedAddress)

// Convert the padded address to felt.Felt and overwrite precomputedAddress
feltAddress, err := utils.HexToFelt(paddedAddress)
if err != nil {
panic(err)
}
precomputedAddress = feltAddress

// Sign the transaction
err = accnt.SignDeployAccountTransaction(context.Background(), &tx.DeployAccountTxn, precomputedAddress)
Expand Down

0 comments on commit 16fd982

Please sign in to comment.