JavaScript
Connecting to the COFFE Smart Wallet API
- Protocol: https Server: coffe.io Port: 8888
- Chain ID: 1ca925bc8fbc1cec262dedd10fd19d9357a1cc8de0bd92e5b61577740af9a3f2
History server
- Protocol: https Server: history.coffe.io Port: 443
History API
JavaScript API
Sending messages to the bot
Client Session ID Generation
function getId(length) {
const validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let array = new Uint8Array(length);
window.crypto.getRandomValues(array);
array = array.map(x => validChars.charCodeAt(x % validChars.length));
const randomState = String.fromCharCode.apply(null, array);
return randomState;
}
Create client
let client_id = getId(24);
let CLIENT = null;
CLIENT = io.connect("https://coffe.io/", { path: "/wssbot" });
CLIENT.on("connect", function () {
console.log("Connect to CLIENT..." );
console.log( CLIENT.io)
});
CLIENT.on("disconnect", function(){
console.log("Disconnected from CLIENT..." );
});
CLIENT.on(client_id , function (receive) {
console.log(receive)
//CLIENT.removeListener(client_id);
if(receive.action == "confirm_action"){
if(receive.code == 1){
if(receive.result==false){
return { result:false, message:receive.message };
}else{
//All is ok.
return { result:true, message:"" };
}
}else if(receive.code == 2){
return { result:false, message:"No confirmation" };
}else if(receive.code == 3){
return { result:false, message:"Authorisation Error" };
}else if(receive.code == 4){
return { result:false, message:"Repeated authorization in telegram is required!" };
}else{
return { result:false, message:"Error" };
}
}
if(receive.action == "auth"){
if(receive.code == 1){
//All is ok. receive.result contain account name
return { result:receive.result, message:"" };
}else if(receive.code == 2){
return { result:false, message:"Canceled" };
}else if(receive.code == 3){
return { result:false, message:"No confirmation" };
}else if(receive.code == 4){
return { result:false, message:"Repeated authorization in telegram is required!" };
}else if(receive.code == 5){
return { result:false, message:"Account not find!" };
}else{
return { result:false, message:"Error" };
}
}
});
Login
function login(){
CLIENT.emit( "bot_module", { action: "auth", client_id:client_id, dapp:$("#dapp_account").val(), user_name: $("#user_name").val()});
}
Create account
function create_account(){
console.log("create_account")
CLIENT.emit( "bot_module", { action: "create_account", client_id:client_id, account:$("#account").val(), public_key:$("#public_key").val()});
}
Transfer
CLIENT.emit( "bot_module", {
action: "confirm_action", client_id:client_id, dapp:"crheroesgame", data: JSON. stringify({
"account": "eosio.token",
"name": "transfer",
"data": {
"from": "rionass1ffor",
"to": "crheroesgame",
"quantity": "1.0000 CFF",
"memo": "my memo",
}
})
});
Action
function action(){
var data = [{
"account": "cryptoweed",
"name": "stksd",
"data": {
"account": "supervisor11",
"type": "seed",
"count": 20,
"generation": 3
}
},
{
"account": "cryptoweed",
"name": "stksd",
"data": {
"account": "supervisor11",
"type": "seed",
"count": 15,
"generation": 2
}
},
{
"account": "cryptoweed",
"name": "stksd",
"data": {
"account": "supervisor11",
"type": "seed",
"count": 10,
"generation": 1
}
}]
CLIENT.emit( "bot_module", { action: "confirm_action", client_id:client_id, dapp:$("#dapp_account").val(), data:data });
}
Last updated on 31st Dec 2021