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

index.html

<div class="row">
   <div class="col">
      <h2>Remove Pet</h2>
      <div>
         <label>ID</label>
         <input type="number" id="remove_pet_id">
      </div>
      <button type="button" id="remove_pet_button" class="btn btn-primary">Remove</button>
   </div>
</div>

main.js

function removePet() {
  var petId = $("#remove_pet_id").val();

  eos.transact({
    actions: [{
      account: contractConfig.code,
      name: "removepet",
      authorization: [{
        actor: account.name,
        permission: account.authority
      }],
      data: {
        id: petId
      }
    }]
  }, {
    blocksBehind: 3,
    expireSeconds: 30
  }).then(function(res) {
    console.log(res);
    getPets();
  }).catch(function(err) {
    alert(err);
  })
}

$(document).ready(function() {
  $("#add_pet_button").click(addPet);
  $("#remove_pet_button").click(removePet);
});

delete a Dog

Dog id
button type="button" id="delete_ dog_button" class="btn btn-primary">delete</button
1 Like