“Error”:”class org.tron.core.services.http.JsonFormat$ParseException : 1:34: INVALID hex String”

Im trying to create a transaction to activate a tron address after creating it. below is my code for creting the address:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> func CreateTRC20Address() (string, *ecdsa.PrivateKey, error) {
// Generate private key
privateKey, err := crypto.GenerateKey()
if err != nil {
return "", nil, err
}
fmt.Println("private key: " + fmt.Sprintf("%v", privateKey))
// Get public key from private key
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
return "", nil, fmt.Errorf("error casting public key to ECDSA")
}
// Step 1: Hash the public key using SHA-256
publicKeyBytes := crypto.FromECDSAPub(publicKeyECDSA)
sha256Hash := sha256.New()
sha256Hash.Write(publicKeyBytes)
sha256HashedPubKey := sha256Hash.Sum(nil)
// Step 2: Hash the result using RIPEMD-160
ripemd160Hash := ripemd160.New()
ripemd160Hash.Write(sha256HashedPubKey)
ripemd160HashedPubKey := ripemd160Hash.Sum(nil)
// Step 3: Add Tron address prefix (0x41) to the RIPEMD-160 hash
tronAddressBytes := append([]byte{0x41}, ripemd160HashedPubKey...)
// Step 4: Base58Check encode the Tron address
checkSum := sha256.Sum256(tronAddressBytes)
checkSum = sha256.Sum256(checkSum[:])
tronAddressBytes = append(tronAddressBytes, checkSum[:4]...)
// Base58 encode the final Tron address
tronAddress := base58.Encode(tronAddressBytes)
return tronAddress, privateKey, nil
}
</code>
<code> func CreateTRC20Address() (string, *ecdsa.PrivateKey, error) { // Generate private key privateKey, err := crypto.GenerateKey() if err != nil { return "", nil, err } fmt.Println("private key: " + fmt.Sprintf("%v", privateKey)) // Get public key from private key publicKey := privateKey.Public() publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) if !ok { return "", nil, fmt.Errorf("error casting public key to ECDSA") } // Step 1: Hash the public key using SHA-256 publicKeyBytes := crypto.FromECDSAPub(publicKeyECDSA) sha256Hash := sha256.New() sha256Hash.Write(publicKeyBytes) sha256HashedPubKey := sha256Hash.Sum(nil) // Step 2: Hash the result using RIPEMD-160 ripemd160Hash := ripemd160.New() ripemd160Hash.Write(sha256HashedPubKey) ripemd160HashedPubKey := ripemd160Hash.Sum(nil) // Step 3: Add Tron address prefix (0x41) to the RIPEMD-160 hash tronAddressBytes := append([]byte{0x41}, ripemd160HashedPubKey...) // Step 4: Base58Check encode the Tron address checkSum := sha256.Sum256(tronAddressBytes) checkSum = sha256.Sum256(checkSum[:]) tronAddressBytes = append(tronAddressBytes, checkSum[:4]...) // Base58 encode the final Tron address tronAddress := base58.Encode(tronAddressBytes) return tronAddress, privateKey, nil } </code>
        func CreateTRC20Address() (string, *ecdsa.PrivateKey, error) {
    // Generate private key
    privateKey, err := crypto.GenerateKey()
    if err != nil {
        return "", nil, err
    }

    fmt.Println("private key: " + fmt.Sprintf("%v", privateKey))

    // Get public key from private key
    publicKey := privateKey.Public()
    publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
    if !ok {
        return "", nil, fmt.Errorf("error casting public key to ECDSA")
    }

    // Step 1: Hash the public key using SHA-256
    publicKeyBytes := crypto.FromECDSAPub(publicKeyECDSA)
    sha256Hash := sha256.New()
    sha256Hash.Write(publicKeyBytes)
    sha256HashedPubKey := sha256Hash.Sum(nil)

    // Step 2: Hash the result using RIPEMD-160
    ripemd160Hash := ripemd160.New()
    ripemd160Hash.Write(sha256HashedPubKey)
    ripemd160HashedPubKey := ripemd160Hash.Sum(nil)

    // Step 3: Add Tron address prefix (0x41) to the RIPEMD-160 hash
    tronAddressBytes := append([]byte{0x41}, ripemd160HashedPubKey...)

    // Step 4: Base58Check encode the Tron address
    checkSum := sha256.Sum256(tronAddressBytes)
    checkSum = sha256.Sum256(checkSum[:])
    tronAddressBytes = append(tronAddressBytes, checkSum[:4]...)

    // Base58 encode the final Tron address
    tronAddress := base58.Encode(tronAddressBytes)

    return tronAddress, privateKey, nil
}

And below is my code for activating the new trc 20 address by sending 0.1trx:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> func CreateTransaction(fromAddress, toAddress string, amount int64) (*Transaction, error) {
// Convert fromAddress and toAddress to hex
fromAddressHex, err := ConvertBase58CheckToHex(fromAddress)
if err != nil {
return nil, fmt.Errorf("invalid fromAddress: %v", err)
}
toAddressHex, err := ConvertBase58CheckToHex(toAddress)
if err != nil {
return nil, fmt.Errorf("invalid toAddress: %v", err)
}
fmt.Printf("fromAddressHex: %s, toAddressHex: %sn", fromAddressHex, toAddressHex)
url := fmt.Sprintf("%s/wallet/createtransaction", tronGridBaseURL)
payload := map[string]interface{}{
"to_address": toAddressHex, // Use hex format
"owner_address": fromAddressHex, // Use hex format
"amount": amount, // Amount in SUN
}
jsonPayload, err := json.Marshal(payload)
if err != nil {
return nil, fmt.Errorf("failed to marshal payload: %v", err)
}
fmt.Printf("CreateTransaction Payload: %sn", string(jsonPayload))
resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonPayload))
if err != nil {
return nil, fmt.Errorf("failed to send create transaction request: %v", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %v", err)
}
fmt.Printf("CreateTransaction Response: %sn", string(body))
var transaction Transaction
err = json.Unmarshal(body, &transaction)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal transaction: %v", err)
}
return &transaction, nil
}
</code>
<code> func CreateTransaction(fromAddress, toAddress string, amount int64) (*Transaction, error) { // Convert fromAddress and toAddress to hex fromAddressHex, err := ConvertBase58CheckToHex(fromAddress) if err != nil { return nil, fmt.Errorf("invalid fromAddress: %v", err) } toAddressHex, err := ConvertBase58CheckToHex(toAddress) if err != nil { return nil, fmt.Errorf("invalid toAddress: %v", err) } fmt.Printf("fromAddressHex: %s, toAddressHex: %sn", fromAddressHex, toAddressHex) url := fmt.Sprintf("%s/wallet/createtransaction", tronGridBaseURL) payload := map[string]interface{}{ "to_address": toAddressHex, // Use hex format "owner_address": fromAddressHex, // Use hex format "amount": amount, // Amount in SUN } jsonPayload, err := json.Marshal(payload) if err != nil { return nil, fmt.Errorf("failed to marshal payload: %v", err) } fmt.Printf("CreateTransaction Payload: %sn", string(jsonPayload)) resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonPayload)) if err != nil { return nil, fmt.Errorf("failed to send create transaction request: %v", err) } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read response body: %v", err) } fmt.Printf("CreateTransaction Response: %sn", string(body)) var transaction Transaction err = json.Unmarshal(body, &transaction) if err != nil { return nil, fmt.Errorf("failed to unmarshal transaction: %v", err) } return &transaction, nil } </code>
        func CreateTransaction(fromAddress, toAddress string, amount int64) (*Transaction, error) {
    // Convert fromAddress and toAddress to hex
    fromAddressHex, err := ConvertBase58CheckToHex(fromAddress)
    if err != nil {
        return nil, fmt.Errorf("invalid fromAddress: %v", err)
    }

    toAddressHex, err := ConvertBase58CheckToHex(toAddress)
    if err != nil {
        return nil, fmt.Errorf("invalid toAddress: %v", err)
    }

    fmt.Printf("fromAddressHex: %s, toAddressHex: %sn", fromAddressHex, toAddressHex)

    url := fmt.Sprintf("%s/wallet/createtransaction", tronGridBaseURL)
    payload := map[string]interface{}{
        "to_address":    toAddressHex,   // Use hex format
        "owner_address": fromAddressHex, // Use hex format
        "amount":        amount,         // Amount in SUN
    }

    jsonPayload, err := json.Marshal(payload)
    if err != nil {
        return nil, fmt.Errorf("failed to marshal payload: %v", err)
    }

    fmt.Printf("CreateTransaction Payload: %sn", string(jsonPayload))

    resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonPayload))
    if err != nil {
        return nil, fmt.Errorf("failed to send create transaction request: %v", err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        return nil, fmt.Errorf("failed to read response body: %v", err)
    }

    fmt.Printf("CreateTransaction Response: %sn", string(body))

    var transaction Transaction
    err = json.Unmarshal(body, &transaction)
    if err != nil {
        return nil, fmt.Errorf("failed to unmarshal transaction: %v", err)
    }

    return &transaction, nil
}


But the response I’m getting is as below:
Create Transaction Response: {“Error”:”class org.tron.core.services.http.JsonFormat$ParseException : 1:34: INVALID hex String”}.
What might I be doing wrong?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật