Dapp Assignment 1

Post your solutions to the remove dog assignment here.

I first checked how it works from the terminal and checked the cpp contract.
cleos push action dogcontract erase ‘[4]’ -p medosync

executed transaction: 6bcf1968898b9f8f428a56a8a99de3a39b679b6a11af957cba1883688edf3f02 96 bytes 257 us
'# dogcontract <= dogcontract::erase {“dog_id”:4}
warning: transaction executed locally, but may not be confirmed by the network yet ]

<div class="row">
    <div class="col">
      <h2>Remove Dog</h2>
      <div>
        <label>Dog Number:</label>
        <input type="number" id="dog_id">
      </div>
      <button type="button" id="remove_dog_button" class="bth btn-secondary">Remove Dog</button>
    </div>
  </div>

function removeDog(){

var dogNumber = $("#dog_id").val();
eos.transact({
actions: [{
account: contractConfig.code,
name: ‘erase’,
authorization: [{
actor: account.name,
permission: account.authority
}],
data: {
dog_id: dogNumber
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30
}).then(function(res){
console.log(res);
//Transaction successful Add Dog
getDogs();
}).catch(function(err){
alert(err);
})
}

1 Like

index.html

      <div class="row">
        <div class="col">
          <h2>Delete a Dog</h2>
          <div>
            <label>Dog Id</label>
            <input type="number" id="dog_id">
          </div>
          <button type="button" id="del_dog_button" class="btn btn-primary">Delete</button>
        </div>
      </div>

main.js

//delete items from blockchain table by id
function deleteDog(){
  var dogId = $("#dog_id").val();
  eos.transact({
    actions:[{
      account: contractConfig.code,
      name: 'erase',
      authorization: [{
        actor: account.name,
        permission: account.authority
      }],
      data:{
        dog_id:dogId
      }
    }]
  },{
    blocksBehind: 3,
    expireSeconds: 30,
  }).then(function(res){
    alert("Dog Deleted, Tx ID: " + res.transaction_id);
    getDogs();
  }).catch(function(err){
    alert(err);
  })
}//end deleteDog

Add this on “$(document).ready(function() …” this is located at the end of main.js file

  //Delete dog button function
  $("#del_dog_button").click(deleteDog);
1 Like