Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Connect MetaMask and Call Contract</title>
    <script src="https://cdn.jsdelivr.net/npm/web3@1.3.6/dist/web3.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            background: linear-gradient(to right, #ff7e5f, #feb47b);
            color: white;
            text-align: center;
            padding: 20px;
        }
        h1, h2 {
            margin-bottom: 20px;
        }
        button {
            background: linear-gradient(to right, #6a11cb, #2575fc);
            border: none;
            color: white;
            padding: 15px 25px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 10px 2px;
            cursor: pointer;
            border-radius: 25px;
            transition: background 0.3s ease;
        }
        button:hover {
            background: linear-gradient(to right, #2575fc, #6a11cb);
        }
        form {
            background: rgba(255, 255, 255, 0.2);
            padding: 20px;
            border-radius: 15px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            display: inline-block;
            text-align: left;
        }
        label {
            display: block;
            margin: 10px 0 5px;
        }
        input[type="text"], input[type="checkbox"] {
            width: calc(100% - 20px);
            padding: 10px;
            border: none;
            border-radius: 5px;
            margin-bottom: 15px;
            display: block;
        }
        input[type="checkbox"] {
            width: auto;
        }
        #result {
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <h1>Connect MetaMask and Call Contract</h1>
    <button id="connectButton">Connect MetaMask</button>
    <div id="account"></div>

    <h2>Call createNFAContract</h2>

    <form id="contractForm">
        <label for="name">Name:</label>
        <input type="text" id="name" name="name">

        <label for="symbol">Symbol:</label>
        <input type="text" id="symbol" name="symbol">

        <h3>AppInfo</h3>
        <label for="routerRequired">Router Required:</label>
        <input type="checkbox" id="routerRequired" name="routerRequired">

        <label for="paymentModel">Payment Model:</label>
        <input type="text" id="paymentModel" name="paymentModel">

        <label for="downloadURIs">Download URIs (comma separated):</label>
        <input type="text" id="downloadURIs" name="downloadURIs">

        <label for="codeHash">Code Hash:</label>
        <input type="text" id="codeHash" name="codeHash">

        <label for="abiURIs">ABI URIs (comma separated):</label>
        <input type="text" id="abiURIs" name="abiURIs">

        <label for="abiHash">ABI Hash:</label>
        <input type="text" id="abiHash" name="abiHash">

        <label for="appVersionId">Version ID:</label>
        <input type="text" id="appVersionId" name="appVersionId">

        <h3>VersionInfo</h3>
        <label for="versionId">Version ID:</label>
        <input type="text" id="versionId" name="versionId">

        <label for="versionDownloadURIs">Download URIs (comma separated):</label>
        <input type="text" id="versionDownloadURIs" name="versionDownloadURIs">

        <label for="versionCodeHash">Code Hash:</label>
        <input type="text" id="versionCodeHash" name="versionCodeHash">

        <label for="versionAbiURIs">ABI URIs (comma separated):</label>
        <input type="text" id="versionAbiURIs" name="versionAbiURIs">

        <label for="versionAbiHash">ABI Hash:</label>
        <input type="text" id="versionAbiHash" name="versionAbiHash">

        <label for="initialOwner">Initial Owner Address:</label>
        <input type="text" id="initialOwner" name="initialOwner">

        <button type="button" id="callContractButton">Call Contract</button>
    </form>
    <div id="result"></div>

    <script>
        let web3;
        let account;
        const contractAddress = "0xe2e43ef883ff83307627c92153c9c356821aff9b";
        const contractABI = [
            {
                "inputs": [
                    {"internalType": "string","name": "name","type": "string"},
                    {"internalType": "string","name": "symbol","type": "string"},
                    {"components": [
                        {"internalType": "bool","name": "routerRequired","type": "bool"},
                        {"internalType": "string","name": "paymentModel","type": "string"},
                        {"internalType": "string[]","name": "downloadURIs","type": "string[]"},
                        {"internalType": "bytes32","name": "codeHash","type": "bytes32"},
                        {"internalType": "string[]","name": "abiURIs","type": "string[]"},
                        {"internalType": "bytes32","name": "abiHash","type": "bytes32"},
                        {"internalType": "string","name": "versionId","type": "string"}
                    ], "internalType": "struct AppInfo", "name": "appInfo", "type": "tuple"},
                    {"components": [
                        {"internalType": "string","name": "versionId","type": "string"},
                        {"internalType": "string[]","name": "downloadURIs","type": "string[]"},
                        {"internalType": "bytes32","name": "codeHash","type": "bytes32"},
                        {"internalType": "string[]","name": "abiURIs","type": "string[]"},
                        {"internalType": "bytes32","name": "abiHash","type": "bytes32"}
                    ], "internalType": "struct VersionInfo", "name": "versionInfo", "type": "tuple"},
                    {"internalType": "address","name": "initialOwner","type": "address"}
                ],
                "name": "createNFAContract",
                "outputs": [{"internalType": "address","name":"","type":"address"}],
                "stateMutability": "nonpayable",
                "type": "function"
            }
        ];

        document.getElementById('connectButton').addEventListener('click', async () => {
            if (typeof window.ethereum !== 'undefined') {
                web3 = new Web3(window.ethereum);
                await window.ethereum.request({ method: 'eth_requestAccounts' });
                const accounts = await web3.eth.getAccounts();
                account = accounts[0];
                document.getElementById('account').innerText = `Connected account: ${account}`;
            } else {
                alert('MetaMask is not installed. Please install MetaMask and try again.');
            }
        });

        document.getElementById('callContractButton').addEventListener('click', async () => {
            if (!account) {
                alert('Please connect MetaMask first.');
                return;
            }

            const name = document.getElementById('name').value;
            const symbol = document.getElementById('symbol').value;
            const routerRequired = document.getElementById('routerRequired').checked;
            const paymentModel = document.getElementById('paymentModel').value;
            const downloadURIs = document.getElementById('downloadURIs').value.split(',');
            const codeHash = document.getElementById('codeHash').value;
            const abiURIs = document.getElementById('abiURIs').value.split(',');
            const abiHash = document.getElementById('abiHash').value;
            const appVersionId = document.getElementById('appVersionId').value;

            const versionId = document.getElementById('versionId').value;
            const versionDownloadURIs = document.getElementById('versionDownloadURIs').value.split(',');
            const versionCodeHash = document.getElementById('versionCodeHash').value;
            const versionAbiURIs = document.getElementById('versionAbiURIs').value.split(',');
            const versionAbiHash = document.getElementById('versionAbiHash').value;

            const initialOwner = document.getElementById('initialOwner').value;

            const contract = new web3.eth.Contract(contractABI, contractAddress);
            try {
                const receipt = await contract.methods.createNFAContract(
                    name,
                    symbol,
                    {
                        routerRequired: routerRequired,
                        paymentModel: paymentModel,
                        downloadURIs: downloadURIs,
                        codeHash: codeHash,
                        abiURIs: abiURIs,
                        abiHash: abiHash,
                        versionId: appVersionId
                    },
                    {
                        versionId: versionId,
                        downloadURIs: versionDownloadURIs,
                        codeHash: versionCodeHash,
                        abiURIs: versionAbiURIs,
                        abiHash: versionAbiHash
                    },
                    initialOwner
                ).send({ from: account });

                document.getElementById('result').innerText = `Transaction successful: ${receipt.transactionHash}`;
            } catch (error) {
                console.error(error);
                document.getElementById('result').innerText = `Error: ${error.message}`;
            }
        });
    </script>
</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console