Using Nameledger Service in Nebulas Dapps

decentralized apps nebulas smart contracts dapps nameledger quickpay

In this post we will be writing about how to use third party smart contracts which are exposed as an api. In our example we will use Nameledger service in your own Nebulas DApps. Lets looks at the code and explain about the same

First call the nameToAddr function of the smart contract address which will give you the address mapped to that address. Then we use nebPay to make the transfer. It’s as simple as that to provide user friendly pay support.

Workflow

// Mainnet nameledger contract address

var contract_address = "n1xD5nS3FNhtsdCMXQvajSD1PgwJt44fKGW";
function nameToAddr() {
    var name = $('#quick-pay-name').val();
    var callFunction = "nameToAddr";
    var callArgs = "[\"" + name.trim() + "\"]";
    nebPay.simulateCall(contract_address, 0, callFunction, callArgs, {
        listener: nameToAddrCallback
    });
}

function nameToAddrCallback(resp) {
  if (resp['result'] === "null") {
    alert("Name not mapped to address. Please verify if the name is correct.")
  } else {
    to = resp['result'].replace(/"/g, '');
    value = $('#quick-pay-amount').val();
    serialNumber = nebPay.pay(to, value, {
        listener: listener  //set listener for extension transaction result
    });
    setTimeout(() => {
        onrefreshClick();   //search transaction result from server (result upload to server by app)
    }, 1000);
  }
}

First call the nameToAddr function of the smart contract address which will give you the address mapped to that address. Then we use nebPay to make the transfer. It’s as simple as that to provide user friendly pay support.

Let me know if you have any feedback.

Comments

comments powered by Disqus