# KLY-WVM - deploy and interact with the smart-contract to WASM vm

## Intro

When you have already written and compiled a smart contract in one of the languages ​​supported by WASM, you can perform the deployment procedure.

Below is an example of a deposit from an account like Ed25519, but you can do a similar procedure from other accounts - BLS, TBLS, PostQuantum.

## Code example

```javascript
let web1337 = new Web1337({

    chainID:'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
    workflowVersion:0,
    nodeURL: 'http://localhost:7332'

});

let contractBytecode = fs.readFileSync('./path/to/your/contract.wasm').toString('hex');

let payload = {

    bytecode:contractBytecode,

    lang:'AssemblyScript', // or Rust

    constructorParams:{
        
        // In case you want to add initial storage to contract - set it as object here
        initStorage:{

            nameHandler:{name:"Name_1"}

        }
    }

}

const shardID = "shard_0";

let keypair = {
    
    pub:"9GQ46rqY238rk2neSwgidap9ww5zbAN4dyqyC7j5ZnBK",
    
    prv:"MC4CAQAwBQYDK2VwBCIEILdhTMVYFz2GP8+uKUA+1FnZTEdN8eHFzbb8400cpEU9",

}

const fee = 0.03

const nonce = await web1337.getAccount(keypair.pub).then(account=>account.nonce+1)

const txType = "WVM_CONTRACT_DEPLOY"

let tx = web1337.createEd25519Transaction(txType,keypair.pub,keypair.prv,nonce,fee,payload)

// Get the ID of contract immediately
const contractID = '0x'+web1337.blake3(tx.creator+tx.nonce)


console.log('Contract ID: '+contractID)

console.log(`Full contract ID: ${shardID}:${contractID}`)

console.log(`TX ID is => `,web1337.blake3(tx.sig))


// Send contract deployment transaction

web1337.sendTransaction(tx).then(()=>{

    console.log('\n\nSent')

}).catch(err=>console.error('Error during contract deployment: ',err))
```

Output:

```code-runner-output
Contract ID: 6a69ea85938d9c1dbfccc60aa7da21aa8326c650392bbe7323fabad985184e32
Full contract ID: shard_0:6a69ea85938d9c1dbfccc60aa7da21aa8326c650392bbe7323fabad985184e32
TX ID is =>  27b01c6b30b5a5ba53179f92e14b131f28caa7d25fb4c6750c1483c92522ec84


Sent
```

## Let's check the explorer

Go to explorer and paste the txid to searchbar. You can also go directly to the page of newly created contract because it's possible to calculate the contractID locally (example above):

<figure><img src="https://3015034387-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNKK8Y1uEALYsObbKnPLt%2Fuploads%2FRZnjZwPC4wKGr9RCxxYy%2Fimage.png?alt=media&#x26;token=a6305737-5d58-41cf-8585-8470acaaede0" alt=""><figcaption></figcaption></figure>

You'll see

<figure><img src="https://3015034387-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNKK8Y1uEALYsObbKnPLt%2Fuploads%2FWDCZdRp6y3cnZId1GBm7%2Fimage.png?alt=media&#x26;token=a8f37161-9cc6-4daa-893b-b2fa0244441a" alt=""><figcaption></figcaption></figure>

It's possible to immediately visit the page of newly created contract by clicking here:

<figure><img src="https://3015034387-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNKK8Y1uEALYsObbKnPLt%2Fuploads%2FPDMXY8hn36HpcLpk7AAj%2Fimage.png?alt=media&#x26;token=a310c1e3-dde8-4924-ac02-2ffa60cca649" alt=""><figcaption></figcaption></figure>

The page of new contract:

<figure><img src="https://3015034387-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNKK8Y1uEALYsObbKnPLt%2Fuploads%2FYNPv4Ko7xnNNfHQR8qUv%2Fimage.png?alt=media&#x26;token=ddb3622d-ce9f-402d-a24a-c969d12d2af4" alt=""><figcaption></figcaption></figure>

And indeed - this contract has only one transaction - deployment:

<figure><img src="https://3015034387-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNKK8Y1uEALYsObbKnPLt%2Fuploads%2FJoFsAnVN9phFGp02GL4V%2Fimage.png?alt=media&#x26;token=986b906a-897f-42ed-9046-ae7e040a256b" alt=""><figcaption></figcaption></figure>

## In case your deployment failed

See[#check-the-reason-of-failed-transaction](https://docs.klyntar.org/web1337/useful-advices-and-faq#check-the-reason-of-failed-transaction "mention")


---

# Agent Instructions: 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://docs.klyntar.org/web1337/transactions-and-smart-contracts/kly-wvm-deploy-and-interact-with-a-smart-contract.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.
