> For the complete documentation index, see [llms.txt](https://int-art.gitbook.io/scripty.sol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://int-art.gitbook.io/scripty.sol/building-html/requesting-html-with-wrapped-url-safe-scripts.md).

# Requesting HTML with Wrapped URL Safe Scripts

This method wraps each script with various `<script></script>` tags. It's tuned for embedding HTML file into JSON metadata for NFT `tokenURI()` method.

This method uses double URL encoded HTML and `<script>` tags. This way, output doesn't need to be converted to base64.&#x20;

#### Supported wrap options:

```javascript
// wrapType = 0
// Wrap URL Safe method doesn't support inline scripts.
// If you set wrapType to 0, ScrityBuilder will encode the 
// given script in base64 and use wrapType 1 wrapping.
```

```javascript
// wrapType = 1
<script src="data:text/javascript;base64,[SCRIPT]"></script>
// double URL encoded:
// %253Cscript%2520src%253D%2522data%253Atext%252Fjavascript%253Bbase64%252C [SCRIPT] %2522%253E%253C%252Fscript%253E
```

<pre class="language-javascript"><code class="lang-javascript">// wrapType = 2
&#x3C;script type="text/javascript+gzip" src="data:text/javascript;base64,[SCRIPT]">&#x3C;/script>
// double URL encoded:
<strong>// %253Cscript%2520type%253D%2522text%252Fjavascript%252Bgzip%2522%2520src%253D%2522data%253Atext%252Fjavascript%253Bbase64%252C [SCRIPT] %2522%253E%253C%252Fscript%253E
</strong></code></pre>

<pre class="language-javascript"><code class="lang-javascript">// wrapType = 3
&#x3C;script type="text/javascript+png" src="data:text/javascript;base64,[SCRIPT]">&#x3C;/script>
// double URL encoded:
<strong>// %253Cscript%2520type%253D%2522text%252Fjavascript%252Bpng%2522%2520src%253D%2522data%253Atext%252Fjavascript%253Bbase64%252C [SCRIPT] %2522%253E%253C%252Fscript%253E
</strong></code></pre>

```javascript
// wrapType = anything other than 0, 1, 2, 3
[wrapPrefix][SCRIPT][wrapSuffix]
// wrapPrefix and wrapSuffix should be double URL encoded
```

#### Example

```solidity
WrappedScriptRequest[] memory requests = new InlineScriptRequest[](5);
requests[0].name = "rawScript";
requests[0].contractAddress = scriptyStorageContractAddress;
requests[0].wrapType = 0;
   
requests[1].name = "base64_encoded_script";
requests[1].contractAddress = scriptyStorageContractAddress;
requests[1].wrapType = 1;

requests[2].name = "base64_encoded_gzip_script";
requests[2].contractAddress = scriptyStorageContractAddress;
requests[2].wrapType = 2;

requests[3].name = "base64_encoded_png_script";
requests[3].contractAddress = scriptyStorageContractAddress;
requests[3].wrapType = 3;

requests[4].name = "script_with_custom_wrap";
requests[4].contractAddress = scriptyStorageContractAddress;
// double encoded:
// - <script type="text/javascript+png" src="data:image/png;base64,[script]"></script>
// - "></script>
requests[4].wrapPrefix = '%253Cscript%2520type%253D%2522text%252Fjavascript%252Bpng%2522%2520src%253D%2522data%253Aimage%252Fpng%253Bbase64%252C';
requests[4].wrapSuffix = '%2522%253E%253C%252Fscript%253E';
requests[4].wrapType = 4;

uint256 bufferSize = 100000;

bytes memory htmlFile = IScriptyBuilder(
    scriptyBuilderAddress
).getHTMLWrappedURLSafe(requests, bufferSize);
```

*(`bufferSize` is set to 100000 as an example. In production, it's important to set an exact size. Please* [*check here*](/scripty.sol/building-html/calculating-buffer-size.md) *to learn more about buffer size.)*

### HTML file output:

```html
<html>
    <body style='margin:0;'>
        <script>[rawScript_not_encoded]</script>
        <script src='data:text/javascript;base64,[base64_encoded_script]'></script>
        <script type="text/javascript+gzip" src="data:text/javascript;base64,[base64_encoded_gzip_script]"></script>
        <script type="text/javascript+png" src="data:text/javascript;base64,[base64_encoded_png_script]"></script>
        <script type="module">[script_with_custom_wrap]</script>
    </body>
</html>
```

Please note that when wrapType is 1 or 2, stored scripts should be in `base64` format.&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://int-art.gitbook.io/scripty.sol/building-html/requesting-html-with-wrapped-url-safe-scripts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
