vanilla delegation with connex

by favo

HTML

<script src="https://unpkg.com/@vechain/connex@2"></script>

<script>
  async function runTest () {
    try {
      document.getElementById('debug').innerHTML = 'Starting Transaction'
      const txId = await testTransfer()
      document.getElementById('debug').innerHTML = `Tx ${txId}`
    }
    catch (err) {
      document.getElementById('debug').innerHTML = err.message
    }
  }
</script>

<center>
  <div id="debug"></div>
  <button onClick="runTest()">Test Transfer</button>
</center>

CSS

* {
  font-family: Courier New;
}

button, div {
  padding: 1rem;
}

JavaScript

const delegateUrl = 'https://sponsor-testnet.vechain.energy/by/1'
const to = '0xac7e94b47f53e97ac46323c7f862ec97237489b1'
const comment = 'Test Transfer with Delegation'

const connex = new Connex({
  node: 'https://testnet.veblocks.net/',
  network: 'test'
})


async function testTransfer () {
  const clauses = [{ 
    to,
    value: 1 + '0'.repeat(18)
  }]

  const { txid } = await connex.vendor.sign('tx', clauses)
    .delegate(delegateUrl)
    .comment(comment)
    .request()
  return txid
}