Created
May 7, 2018 14:10
-
-
Save yupnano/21fb8361b802988cdfce929e85391aa7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="nebPay.js"></script> | |
<script > | |
var NebPay = require("nebpay"); | |
var nebPay = new NebPay(); | |
var serialNumber; //交易序列号 | |
var intervalQuery; //定时查询交易结果 | |
//点击按钮发起交易, 这里为调用智能合约的例子 | |
function onButtonClick() { | |
var to = dappAddress; //Dapp的合约地址 | |
var value = "0"; | |
var callFunction = "" //调用的函数名称 | |
var callArgs = "" //参数格式为参数数组的JSON字符串, 比如'["arg"]','["arg1","arg2]' | |
var options = { | |
goods: { //商品描述 | |
name: "example" | |
} | |
} | |
//发送交易(发起智能合约调用) | |
serialNumber = nebPay.call(to, value, callFunction, callArgs, options); | |
//设置定时查询交易结果 | |
intervalQuery = setInterval(function() { | |
funcIntervalQuery(); | |
}, 5000); | |
} | |
//查询交易结果. queryPayInfo返回的是一个Promise对象. | |
function funcIntervalQuery() { | |
nebPay.queryPayInfo(serialNumber) //search transaction result from server (result upload to server by app) | |
.then(function (resp) { | |
console.log("tx result: " + resp) //resp is a JSON string | |
var respObject = JSON.parse(resp) | |
if(respObject.code === 0){ | |
//交易成功, 处理相关任务 | |
clearInterval(intervalQuery) //清除定时查询 | |
} | |
}) | |
.catch(function (err) { | |
console.log(err); | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment