📃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

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:

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):

You'll see

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

The page of new contract:

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

In case your deployment failed

SeeCheck the reason of failed transaction

Last updated

Was this helpful?