พัฒนาด้วย PIXA Keychain
แอปส่งคำขอ ผู้ใช้อ่านในหน้าต่างของกระเป๋าเงิน และฟังก์ชันเรียกกลับได้รับคำตอบ คุณไม่เคยถือคีย์และไม่ต้องสมัครอะไร
กำลังค้นหา PIXA Keychain ในเบราว์เซอร์นี้
ค้นหากระเป๋าเงิน
ส่วนขยายเพิ่ม window.pixa_keychain ในทุกหน้าที่ใช้ https:// และใน localhost กับ 127.0.0.1 ขณะพัฒนา โดยจะปรากฏหลังหน้าโหลดแล้ว จึงควรรอสักครู่ก่อนบอกว่าไม่มี
ถ้าไม่มี ให้ลิงก์ไปที่ pixtopia.net/keychain ไม่ทำงานบนโทรศัพท์ จึงควรมีทางเข้าอื่นให้
async function findKeychain(ms = 2000) {
const end = Date.now() + ms;
while (!window.pixa_keychain && Date.now() < end) {
await new Promise((resolve) => setTimeout(resolve, 100));
}
return window.pixa_keychain ?? null;
}
ให้คนเข้าสู่ระบบ
เซิร์ฟเวอร์สร้างข้อความใช้ครั้งเดียว กระเป๋าเงินลงนามด้วยคีย์โพสต์ของผู้ใช้ แล้วเซิร์ฟเวอร์ตรวจลายเซ็นเทียบกับคีย์ของบัญชีบนเชน ไม่มีการส่งธุรกรรมและไม่มีค่าใช้จ่าย
- ส่ง
nullเป็นบัญชี แล้วผู้ใช้เลือกบัญชีในกระเป๋าเงิน คำตอบจะระบุบัญชีในdata.username - กระเป๋าเงินแสดงข้อความตรงตามที่เขียน จึงควรเขียนให้คนอ่านและระบุชื่อเว็บไซต์
- ให้ข้อความใช้ได้ครั้งเดียวและกำหนดวันหมดอายุ เพื่อไม่ให้ใช้ลายเซ็นซ้ำ
- ตรวจบนเซิร์ฟเวอร์เสมอ หน้าเว็บแยกส่วนขยายจริงจากสคริปต์แอบอ้างไม่ได้ และ
data.usernameยังเป็นเพียงคำกล่าวอ้างจนกว่าลายเซ็นจะพิสูจน์
const keychain = await findKeychain();
if (!keychain) return showGetTheWallet();
// A request opens a window, so only do this after a tap.
const { message } = await post('/auth/challenge');
keychain.requestSignBuffer(null, message, 'Posting', async (answer) => {
if (!answer.success) return; // They said no.
await post('/auth/verify', {
account: answer.data.username,
message,
signature: answer.result,
});
});
import { secp256k1 } from '@noble/curves/secp256k1.js';
import { ripemd160 } from '@noble/hashes/legacy.js';
import { sha256 } from '@noble/hashes/sha2.js';
import { hexToBytes, utf8ToBytes } from '@noble/hashes/utils.js';
import { base58 } from '@scure/base';
// The key that made a signature. Pixa keys look like PIX...
function recoverKey(message, signature) {
const bytes = hexToBytes(signature);
bytes[0] -= 31; // Pixa, like Hive, adds 31 to the recovery number.
const point = secp256k1.recoverPublicKey(
bytes,
sha256(utf8ToBytes(message)),
{ prehash: false },
);
const withCheck = new Uint8Array(37);
withCheck.set(point);
withCheck.set(ripemd160(point).slice(0, 4), 33);
return 'PIX' + base58.encode(withCheck);
}
async function verifySignIn({ account, message, signature }) {
// First make sure this is a message you issued, unused and unexpired.
const response = await fetch('https://api.pixagram.com', {
method: 'POST',
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'condenser_api.get_accounts',
params: [[account]],
}),
});
const [onChain] = (await response.json()).result;
if (!onChain) return false;
const key = recoverKey(message, signature);
const { key_auths, weight_threshold } = onChain.posting;
const entry = key_auths.find(([known]) => known === key);
return Boolean(entry) && entry[1] >= weight_threshold;
}
ลองที่นี่
นี่คือขั้นตอนเดียวกันที่ทำงานจริงบนหน้านี้ ลงนามข้อความทดสอบด้วยคีย์โพสต์ แล้วกู้คีย์จากลายเซ็นและค้นหาบนเชน ไม่มีการส่งธุรกรรม ไม่เก็บลายเซ็นหรือส่งไปที่ใด
ต้องมี PIXA Keychain ในเบราว์เซอร์นี้เพื่อทดลอง
ข้อความ
คำตอบของกระเป๋าเงิน
ลงนามและส่ง
สำหรับการทำงานทั่วไป ขอสิ่งที่ต้องการแล้วกระเป๋าเงินจะสร้างธุรกรรม แสดงด้วยคำที่เข้าใจง่าย ลงนามและส่งผ่านโหนดของผู้ใช้
requestVoteสำหรับถูกใจ น้ำหนักตั้งแต่ -10000 ถึง 10000requestCustomJsonสำหรับติดตามและข้อมูลของแอป แสดงข้อความ ID และข้อมูลrequestPostสำหรับโพสต์และการตอบกลับrequestTransferและคำขอเกี่ยวกับเงินอื่น ๆrequestBroadcastสำหรับการดำเนินการอื่นrequestSignTxหากต้องส่งธุรกรรมเอง
ตั้งค่ารางวัลโพสต์ใน requestPost แล้วจะแสดงในการตรวจทานทุกครั้ง ต้องระบุผู้เขียนและ permlink นั้น
const follow = JSON.stringify(['follow', {
follower: account,
following: 'pixtopia',
what: ['blog'],
}]);
keychain.requestCustomJson(
account,
'follow',
'Posting',
follow,
'Follow @pixtopia',
(answer) => {
if (answer.success) showFollowing(answer.result.tx_id);
},
);
const node = 'https://api.pixagram.com';
const call = async (method, params) =>
(await (await fetch(node, {
method: 'POST',
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }),
})).json()).result;
const { head_block_number, head_block_id } =
await call('condenser_api.get_dynamic_global_properties', []);
const prefix = head_block_id
.slice(8, 16).match(/../g).reverse().join('');
const expires = new Date(Date.now() + 600000);
const transaction = {
ref_block_num: head_block_number & 0xffff,
ref_block_prefix: parseInt(prefix, 16),
expiration: expires.toISOString().slice(0, 19),
operations: [
['vote', { voter: account, author, permlink, weight: 5000 }],
],
extensions: [],
};
keychain.requestSignTx(account, transaction, 'Posting', async (answer) => {
if (answer.success) {
await call('condenser_api.broadcast_transaction', [answer.result]);
}
});
ควรขอคีย์ใด
ขอสิทธิ์น้อยที่สุดเท่าที่จำเป็น ผู้ใช้สังเกตได้
โพสต์
ถูกใจ โพสต์ ตอบกลับ ติดตาม และ custom_json ของคุณ เป็นคีย์เดียวที่ใช้ “ไม่ต้องถามอีก” ได้
แอ็กทีฟ
เงินและการกำกับดูแล: โอน เงินออม พลัง การมอบหมาย และโหวตพยาน เปิดหน้าต่างเสมอ
บันทึก
เข้ารหัสและอ่านข้อความส่วนตัว เปิดหน้าต่างเสมอ
เจ้าของ
ปฏิเสธเสมอ กระเป๋าเงินไม่เก็บคีย์เจ้าของ จึงอย่าสร้างสิ่งที่ต้องใช้
อ่านคำตอบ
ทุกฟังก์ชันเรียกกลับได้ออบเจ็กต์หนึ่งรายการ ตรวจ success ก่อนใช้ result
| ฟิลด์ | ความหมาย |
|---|---|
success | true ถ้าสำเร็จ |
result | สิ่งที่คำขอสร้าง เช่น ลายเซ็นหรือผลการส่งธุรกรรม |
error | เหตุผลที่ไม่สำเร็จ |
message | ประโยคที่คุณแสดงได้ |
data | คำขอตามที่กระเป๋าเงินได้รับ |
publicKey | คีย์สาธารณะที่ลงนาม ถ้ามี |
request_id | หมายเลขคำขอนี้ |
ข้อผิดพลาดที่ควรจัดการ
user_cancel | ผู้ใช้ปฏิเสธ ไม่ต้องแจ้งอะไรเพิ่ม |
incomplete | คำขอไม่ถูกต้อง message บอกเหตุผล |
ignored | คำขอใหม่กว่าจากหน้านี้แทนที่คำขอนี้ |
busy | คำขอล่าสุดกำลังส่งแล้ว ให้รอ |
// A page gets one request at a time, so they wait their turn.
let line = Promise.resolve();
function ask(send) {
const turn = line.then(() => new Promise((resolve, reject) => {
send(window.pixa_keychain, (answer) => {
if (answer.success) return resolve(answer);
const error = new Error(answer.message);
error.code = answer.error;
reject(error);
});
}));
line = turn.catch(() => undefined);
return turn;
}
const answer = await ask((keychain, done) =>
keychain.requestVote(account, permlink, author, 5000, done));
สิ่งที่ควรรู้
- อย่าขอโดยผู้ใช้ไม่ได้ทำอะไร คำขอเปิดหน้าต่าง จึงควรเกิดจากการกระทำของผู้ใช้
- ทีละคำขอ คำขอใหม่แทนคำขอที่ยังรอผู้ใช้ ซึ่งตอบกลับเป็น
ignoredและคำขอใหม่จะถูกปฏิเสธด้วยbusyถ้าคำขอก่อนกำลังส่งแล้ว - จำนวนเงิน เป็นสตริงทศนิยมสามตำแหน่ง (
"1.000") ในหน่วยPIXAและPXSการมอบหมายใช้PPหรือVESTSคำขอที่ใช้HIVEหรือHBDถูกปฏิเสธ - ข้อความ ลงนามเป็นข้อความตรงตามที่ผู้ใช้อ่าน กระเป๋าเงินไม่ถอดรหัสไบต์จาก JSON และปฏิเสธข้อความที่ขึ้นต้นด้วย ID เชนของ Pixa เพราะอาจลงนามเป็นธุรกรรมได้
- คุณเป็นผู้รับผิดชอบการอ่าน เรียกโหนด Pixa เองเพื่ออ่านยอดคงเหลือ โพสต์ และบัญชี กระเป๋าเงินลงนามเท่านั้น
- โหนดเป็นของผู้ใช้ ยังรับ
rpcแต่จะไม่ใช้ - หัวเรื่องมาจากกระเป๋าเงิน ไม่ใช้
titleในrequestSignBufferเช่นกัน สิ่งที่เว็บไซต์เขียนแสดงเป็นค่าเท่านั้น จึงแอบอ้างว่าเป็นคำพูดของกระเป๋าเงินไม่ได้ - น้ำหนัก ในคำขอสิทธิ์เป็นจำนวนเต็มตั้งแต่ 1 ถึง 65535
- ถ้าอ่านไม่ได้ จะบอกตรง ๆ การดำเนินการที่อธิบายไม่ได้จะแสดงคำเตือนและธุรกรรมดิบ และอนุมัติล่วงหน้าไม่ได้ รวมถึง
custom_jsonที่ส่งผ่านrequestBroadcastหรือrequestSignTxเว้นแต่เป็นการติดตามหรือการกระทำในพอร์ทัล ส่งข้อมูลแอปด้วยrequestCustomJsonแทน เพื่อให้ผู้ใช้เห็นข้อความและเลือกไม่ให้ถามอีกสำหรับ ID นั้น
ย้ายจาก Hive Keychain
คำขอมีโครงสร้างเดียวกัน เว็บไซต์ส่วนใหญ่จึงแค่เปลี่ยนชื่อตัวแปรส่วนกลางและใช้โทเคนของ Pixa ทั้งสองส่วนขยายอยู่ในเบราว์เซอร์เดียวกันได้ เพราะไม่มีชื่อที่ใช้ร่วมกับ Hive Keychain
- ใช้
PIXAและPXSและใช้pixaกับpxsในชื่อฟิลด์ เช่นpercent_pxs - คีย์สาธารณะขึ้นต้นด้วย
PIXและโหนดคือapi.pixagram.com requestSignedCallปิดใช้งาน ใช้requestBroadcastหรือrequestSignTx- ไม่มี Hive Engine การแลกเปลี่ยน การลงนามหลายฝ่าย หรือ HiveAuth ที่นี่
const keychain = window.pixa_keychain;
ทดสอบแอป
ที่เก็บโค้ดมีหน้าพร้อมแบบฟอร์มสำหรับทุกคำขอ ให้บริการจากที่อยู่ในเครื่อง แล้วเปิดโดยติดตั้งส่วนขยายไว้
คำขอจากหน้านั้นเป็นของจริง เช่นเดียวกับทุกสิ่งที่แอปส่ง จึงควรใช้บัญชีทดสอบที่ไม่มีสิ่งสำคัญให้เสีย
git clone https://github.com/elmerlin/pixa-keychain.git
cd pixa-keychain/example
python3 -m http.server 1337
# Then open http://localhost:1337/main.html
คำขอทั้งหมด
ส่วนใหญ่รับบัญชีเป็นตัวแรก ฟังก์ชันเรียกกลับอยู่ใกล้ท้าย และตามด้วยพารามิเตอร์เสริม
ค้นหากระเป๋าเงินและลงนามข้อความ
requestHandshakeตรวจว่ามีกระเป๋าเงินอยู่ ไม่เปิดหน้าต่าง
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
callback | function | ยืนยันการติดตั้ง Keychain (ไม่มีพารามิเตอร์) |
requestSignBufferลงนามข้อความ ซึ่งใช้ให้คนเข้าสู่ระบบ
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account (ไม่บังคับ) | String | บัญชี Pixa ที่ทำคำขอ ถ้าเป็น null ผู้ใช้เลือกบัญชีจากรายการแบบเลื่อนลงได้ |
message | String | ข้อความที่ให้บัญชีลงนาม |
key | String | ประเภทคีย์ ใช้ 'Posting','Active' หรือ 'Memo' ได้ |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
title (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินเขียนหัวเรื่องเอง |
requestVerifyKeyขอให้กระเป๋าเงินถอดรหัสข้อความเพื่อแสดงว่าถือคีย์อยู่
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account | String | บัญชี Pixa ที่ทำคำขอ |
message | String | ข้อความที่ให้บัญชีถอดรหัส |
key | String | ประเภทคีย์ ใช้ 'Posting','Active' หรือ 'Memo' ได้ |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
const keychain = window.pixa_keychain;
keychain.requestVerifyKey('pixtopia', encodedMessage, 'Posting', (response) => {
if (response.success === true) {
const decodedMessage = response.result;
}
});requestEncodeMessageเข้ารหัสข้อความให้อีกบัญชี
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username | String | บัญชี Pixa ที่ทำคำขอ |
receiver | String | บัญชีที่จะถอดรหัสสตริง |
message | String | ข้อความที่จะเข้ารหัส ต้องขึ้นต้นด้วย # |
key | String | ประเภทคีย์ ใช้ 'Posting','Active' หรือ 'Memo' ได้ |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
const keychain = window.pixa_keychain;
const message = '#' + username + Date.now();
keychain.requestEncodeMessage(username, myUsername, message, 'Memo', (response) => {
if (response.success) {
const encodedMessage = response.result;
// Send message to a server where you can use your private key to decode it
}
});requestEncodeWithKeysเข้ารหัสข้อความสำหรับคีย์สาธารณะหลายคีย์
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username | String | บัญชี Pixa ที่ทำคำขอ |
publicKeys | Array<String> | คีย์ที่ถอดรหัสสตริงได้ |
message | String | ข้อความที่จะเข้ารหัส ต้องขึ้นต้นด้วย # |
key | String | ประเภทคีย์ ใช้ 'Posting','Active' หรือ 'Memo' ได้ |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
const keychain = window.pixa_keychain;
const message = '#' + username + Date.now();
keychain.requestEncodeWithKeys(username, [pubKey1, pubKey2], message, 'Memo', (response) => {
if (response.success) {
const encodedMessages = response.result;
// Send message to a server where you can use your private key to decode it
}
});โพสต์และโซเชียล
requestPostเผยแพร่โพสต์หรือการตอบกลับ
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account | String | บัญชี Pixa ที่ทำคำขอ |
title | String | ชื่อเรื่องโพสต์ |
body | String | เนื้อหาโพสต์ |
parent_perm | String | Permlink ของโพสต์แม่ หรือแท็กหลักสำหรับโพสต์ระดับบนสุด |
parent_account | String | ผู้เขียนโพสต์แม่ ส่ง '' สำหรับโพสต์ระดับบนสุด |
json_metadata | String | ข้อมูลเมตาของโพสต์ในรูป JSON |
permlink | String | Permlink ของโพสต์ |
comment_options | String | การตั้งค่ารางวัลโพสต์ในรูป JSON หรือ '' ต้องระบุผู้เขียนและ permlink นี้ และจะแสดงในการตรวจทาน |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
const keychain = window.pixa_keychain;
keychain.requestPost(
'pixtopia',
'Hello World!',
'This is a blog post',
'blog',
'',
JSON.stringify({ format: 'markdown', tags: ['blog'] }),
'hello-world',
JSON.stringify({
author: 'pixtopia',
permlink: 'hello-world',
max_accepted_payout: '100000.000 PXS',
percent_pxs: 10000,
allow_votes: true,
allow_curation_rewards: true,
extensions: [[0, { beneficiaries: [{ account: 'pixa.team', weight: 1000 }] }]],
}),
(response) => {
console.log(response);
},
);requestVoteถูกใจหรือดาวน์โหวตโพสต์
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account | String | บัญชี Pixa ที่ทำคำขอ |
permlink | String | Permlink ของโพสต์ |
author | String | ผู้เขียนโพสต์ |
weight | Number | น้ำหนักโหวตระหว่าง -10,000 (-100%) ถึง 10,000 (100%) |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
// Upvote with 50% weight
const keychain = window.pixa_keychain;
keychain.requestVote('pixa.team', 'hello-world', 'pixtopia', 5000, (response) => {
console.log(response);
});requestCustomJsonส่ง custom_json เช่น การติดตามหรือข้อมูลของแอป
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account (ไม่บังคับ) | String | บัญชี Pixa ที่ทำคำขอ ถ้าเป็น null ผู้ใช้เลือกบัญชีจากรายการแบบเลื่อนลงได้ |
id | String | ประเภท custom_json ที่จะส่ง |
key | String | ประเภทคีย์ ใช้ 'Posting' หรือ 'Active' ได้ |
json | String | JSON แบบกำหนดเองที่แปลงเป็นสตริง |
display_msg | String | ข้อความอธิบายให้ผู้ใช้ทราบว่าการส่งนี้เกี่ยวกับอะไร |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
const keychain = window.pixa_keychain;
keychain.requestCustomJson(null, 'my-app', 'Posting', JSON.stringify({ action: 'hello' }), 'Say hello in My App', (response) => {
console.log(response);
});ธุรกรรมใดก็ได้
requestBroadcastส่งการดำเนินการใด ๆ ในธุรกรรมเดียว
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account | String | บัญชี Pixa ที่ทำคำขอ |
operations | Array | อาร์เรย์การดำเนินการที่จะส่ง |
key | String | ประเภทคีย์ ใช้ 'Posting' หรือ 'Active' ได้ |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
const keychain = window.pixa_keychain;
keychain.requestBroadcast('pixa.team', [
[
'account_witness_vote',
{
account: 'pixa.team',
witness: 'pixtopia',
approve: true
}
]
], 'Active', (response) => {
console.log(response);
});requestSignTxลงนามธุรกรรมที่คุณเตรียม เพื่อให้คุณส่งเอง
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account | String | บัญชี Pixa ที่ทำคำขอ |
tx | Object | ธุรกรรมที่ยังไม่ลงนาม |
key | String | ประเภทคีย์ ใช้ 'Posting' หรือ 'Active' ได้ |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
// This example would be done much easier with requestBroadcast
const node = 'https://api.pixagram.com';
const call = async (method, params) =>
(await (await fetch(node, {
method: 'POST',
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }),
})).json()).result;
const { head_block_number, head_block_id } = await call('condenser_api.get_dynamic_global_properties', []);
const prefix = head_block_id.slice(8, 16).match(/../g).reverse().join('');
const tx = {
ref_block_num: head_block_number & 0xffff,
ref_block_prefix: parseInt(prefix, 16),
expiration: new Date(Date.now() + 600000).toISOString().slice(0, 19),
operations: [...], // Add operations here
extensions: [],
};
window.pixa_keychain.requestSignTx(username, tx, 'Posting', async (response) => {
if (response.success) {
await call('condenser_api.broadcast_transaction', [response.result]);
}
});requestSignedCallปิดใช้งาน ใช้ requestBroadcast หรือ requestSignTx
เงิน
requestTransferส่ง PIXA หรือ PXS
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account | String | บัญชี Pixa ที่ทำคำขอ |
to | String | บัญชี Pixa ที่รับการโอน |
amount | String | จำนวนที่จะโอน ต้องมีทศนิยม 3 ตำแหน่ง |
memo | String | บันทึกจะเข้ารหัสอัตโนมัติถ้าขึ้นต้นด้วย '#' และมีคีย์บันทึกข้อความใน Keychain อีกทั้งจะบังคับบัญชีที่ใช้ ไม่ว่าพารามิเตอร์ 'enforce' จะเป็นอย่างไร |
currency | String | 'PIXA' หรือ 'PXS' |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
enforce (ไม่บังคับ) | boolean | ถ้าเป็น true ผู้ใช้เลือกโอนจากบัญชีอื่นไม่ได้ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
const keychain = window.pixa_keychain;
keychain.requestTransfer(username, toUsername, '1.000', '', 'PIXA', (response) => {
console.log(response)
}, true);requestRecurrentTransferตั้งการโอนซ้ำ
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username (ไม่บังคับ) | String | บัญชี Pixa ที่ทำคำขอ |
to | String | บัญชี Pixa ที่รับการโอน |
amount | String | จำนวนที่ส่งแต่ละครั้ง |
currency | String | PIXA หรือ PXS บนเครือข่ายหลัก |
memo | String | บันทึกการโอน |
recurrence | Number | ความถี่การจ่ายเป็นชั่วโมง อย่างน้อย 24 |
executions | Number | จำนวนครั้งที่จ่ายซ้ำ อย่างน้อย 2 |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
pair_id (ไม่บังคับ) | Number | ID คู่ของการโอนซ้ำ |
// Let's send @pixtopia 5 PIXA a day
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestRecurrentTransfer(null, 'pixtopia', '5.000', 'PIXA', '', 24, 7, (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}requestSavingsOperationย้าย PIXA หรือ PXS เข้าออกเงินออม
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username | String | บัญชี Pixa ที่ทำคำขอ |
to | String | บัญชีที่รับการโอนเงินออม |
amount | String | จำนวนที่จะโอน ต้องมีทศนิยม 3 ตำแหน่ง |
currency | String | 'PIXA' หรือ 'PXS' |
operation | String | 'deposit' หรือ 'withdraw' |
memo (ไม่บังคับ) | String | บันทึกที่แนบกับการดำเนินการเงินออม |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
const keychain = window.pixa_keychain;
keychain.requestSavingsOperation(username, toUsername, '1.000', 'PXS', 'deposit', 'test memo', (response) => {
console.log(response);
});requestConversionแปลงระหว่าง PXS และ PIXA
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username | String | บัญชี Pixa ที่ทำคำขอ |
amount | String | จำนวนที่จะแปลง |
collaterized | Boolean | true เพื่อแปลง PIXA เป็น PXS และ false เพื่อแปลง PXS เป็น PIXA |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
// Convert 5 PIXA to PXS
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestConversion(username, '5.000', true, (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}พลังและการมอบหมาย
requestPowerUpเปลี่ยน PIXA เป็น Pixa Power
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username | String | บัญชี Pixa ที่ทำคำขอ |
recipient | String | บัญชีที่รับพลัง |
hive | String | จำนวน PIXA ที่จะเพิ่มพลัง |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
// Power up 5 PP
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestPowerUp(username, username, '5.000', (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}requestPowerDownเริ่มเปลี่ยน Pixa Power กลับเป็น PIXA
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username | String | บัญชี Pixa ที่ทำคำขอ |
hive_power | String | จำนวน PIXA ที่จะถอนพลัง |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
// Power down 5 PP
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestPowerDown(username, '5.000', (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}requestDelegationให้บัญชีอื่นยืม Pixa Power
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username (ไม่บังคับ) | String | บัญชี Pixa ที่ทำคำขอ ถ้าเป็น null ผู้ใช้เลือกบัญชีจากรายการแบบเลื่อนลงได้ |
delegatee | String | บัญชีที่รับการมอบหมาย |
amount | String | จำนวนที่จะโอน ต้องมีทศนิยม 3 ตำแหน่งสำหรับ PP และ 6 สำหรับ VESTS |
unit | String | PP หรือ VESTS |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestDelegation(null, 'pixtopia', '1.000', 'PP', (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}การกำกับดูแล
requestWitnessVoteโหวตให้พยานหรือถอนโหวต
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username (ไม่บังคับ) | String | บัญชี Pixa ที่ทำคำขอ ถ้าเป็น null ผู้ใช้เลือกบัญชีจากรายการแบบเลื่อนลงได้ |
witness | String | บัญชีที่รับโหวตพยาน |
vote | boolean | ตั้ง true เพื่อโหวตพยาน และ false เพื่อถอนโหวต |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
// Unvote our witness vote for @pixtopia
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestWitnessVote(null, 'pixtopia', false, (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}requestProxyตั้งผู้โหวตแทนบัญชี
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username (ไม่บังคับ) | String | บัญชี Pixa ที่ทำคำขอ ถ้าเป็น null ผู้ใช้เลือกบัญชีจากรายการแบบเลื่อนลงได้ |
proxy | String | บัญชีที่จะเป็นผู้โหวตแทน ใช้สตริงว่าง ('') เพื่อลบผู้โหวตแทน |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
// Let @pixtopia use our voting power in governance votes
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestProxy(null, 'pixtopia', (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}
// Remove voting proxy
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestProxy(null, '', (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}requestCreateProposalสร้างข้อเสนอสำหรับกองทุน Pixa
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username | String | บัญชี Pixa ที่ทำคำขอ |
receiver | String | บัญชีที่รับเงินทุนหากข้อเสนอผ่านการโหวต |
subject | String | ชื่อข้อเสนอ |
permlink | String | Permlink ไปยังคำอธิบายข้อเสนอ |
daily_pay | String | จำนวนรายวันที่ receiver จะได้รับ เช่น '10.000 PXS' |
start | String | วันที่เริ่ม เช่น '2027-01-01T00:00:00' |
end | String | วันที่สิ้นสุดในรูปแบบเดียวกัน |
extensions | String | อาร์เรย์ส่วนขยายที่แปลงเป็นสตริง |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestCreateProposal('pixtopia', 'pixtopia', 'PIXA Keychain development', 'pixa-keychain-proposal', '10.000 PXS', '2027-01-01T00:00:00', '2027-12-31T00:00:00', JSON.stringify([]), (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}requestRemoveProposalลบข้อเสนอของบัญชีเอง
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username | String | บัญชี Pixa ที่ทำคำขอ |
proposal_ids | String | อาร์เรย์ ID ข้อเสนอที่จะลบ แปลงเป็นสตริง |
extensions | String | อาร์เรย์ส่วนขยายที่แปลงเป็นสตริง |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestRemoveProposal(username, JSON.stringify([216]), JSON.stringify([]), (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}requestUpdateProposalVoteโหวตข้อเสนอหรือถอนโหวต
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username | String | บัญชี Pixa ที่ทำคำขอ |
proposal_ids | String | อาร์เรย์ ID ข้อเสนอที่จะโหวต แปลงเป็นสตริง |
approve | boolean | ตั้ง true เพื่อสนับสนุนข้อเสนอ และ false เพื่อถอนโหวต |
extensions | String | อาร์เรย์ส่วนขยายที่แปลงเป็นสตริง |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
// Approve a proposal
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestUpdateProposalVote(username, JSON.stringify([216]), true, JSON.stringify([]), (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}
// Unapprove a proposal
if (window.pixa_keychain) {
const keychain = window.pixa_keychain;
keychain.requestUpdateProposalVote(username, JSON.stringify([216]), false, JSON.stringify([]), (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}บัญชีและผู้ควบคุม
requestAddAccountเสนอให้เพิ่มคีย์บัญชีในกระเป๋าเงิน
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username | String | ชื่อผู้ใช้ของบัญชีที่จะเพิ่ม |
keys | Object | คีย์ส่วนตัวของบัญชี: {active:'...',posting:'...',memo:'...'} ต้องระบุอย่างน้อยหนึ่งคีย์ หรือระบุบัญชีที่ได้รับสิทธิ์ด้วย @${username} |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
if (window.pixa_keychain) {
const postingKey = '...';
const keychain = window.pixa_keychain;
keychain.requestAddAccount(username, {
posting: postingKey
}, (response) => {
console.log(response);
});
} else {
alert('PIXA Keychain is not installed');
}requestCreateClaimedAccountสร้างบัญชีด้วยตั๋ว
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
username | String | บัญชี Pixa ที่ทำคำขอ |
new_account | String | บัญชีใหม่ที่จะสร้าง |
owner | String | สิทธิ์เจ้าของในรูป JSON |
active | String | สิทธิ์แอ็กทีฟในรูป JSON |
posting | String | สิทธิ์โพสต์ในรูป JSON |
memo | String | คีย์บันทึกข้อความสาธารณะ |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
requestAddAccountAuthorityให้บัญชีอื่นมีสิทธิ์เหนือบัญชีนี้
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account | String | บัญชี Pixa ที่ทำคำขอ |
authorizedUsername | String | บัญชีที่ได้รับสิทธิ์ |
role | String | ประเภทสิทธิ์ ใช้ 'Posting' หรือ 'Active' ได้ |
weight | number | น้ำหนักสิทธิ์ |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
// Gives @pixtopia active authority with weight 2 to `account`
const keychain = window.pixa_keychain
keychain.requestAddAccountAuthority(account, 'pixtopia', 'Active', 2, (response) => {
console.log(response);
});requestRemoveAccountAuthorityถอนสิทธิ์ของบัญชี
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account | String | บัญชี Pixa ที่ทำคำขอ |
authorizedUsername | String | บัญชีที่จะเสียสิทธิ์ |
role | String | ประเภทสิทธิ์ ใช้ 'Posting' หรือ 'Active' ได้ |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
// Removes @pixtopia's active authority from `account`
const keychain = window.pixa_keychain;
keychain.requestRemoveAccountAuthority(account, 'pixtopia', 'Active', (response) => {
console.log(response);
});requestAddKeyAuthorityเพิ่มคีย์สาธารณะในสิทธิ์ของบัญชีนี้
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account | String | บัญชี Pixa ที่ทำคำขอ |
authorizedKey | String | คีย์สาธารณะใหม่ที่จะผูกกับบัญชี |
role | String | ประเภทสิทธิ์ ใช้ 'Posting' หรือ 'Active' ได้ |
weight | number | น้ำหนักสิทธิ์ของคีย์ |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
const keychain = window.pixa_keychain;
keychain.requestAddKeyAuthority(username, publicKey, 'Posting', 1, (response) => {
console.log(response);
});requestRemoveKeyAuthorityนำคีย์สาธารณะออกจากสิทธิ์ของบัญชีนี้
| พารามิเตอร์ | ชนิด | ความหมาย |
|---|---|---|
account | String | บัญชี Pixa ที่ทำคำขอ |
authorizedKey | String | คีย์ที่จะลบ (คีย์สาธารณะ) |
role | String | ประเภทสิทธิ์ ใช้ 'Posting' หรือ 'Active' ได้ |
callback | function | ฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ |
rpc (ไม่บังคับ) | String | ไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ |
const keychain = window.pixa_keychain;
keychain.requestRemoveKeyAuthority(username, publicKey, 'Posting', (response) => {
console.log(response);
});ติดขัดหรือพบสิ่งที่ขาดไป?
เปิดประเด็นหรือส่งการแก้ไข ทุกอย่างอยู่บน GitHub ถ้าคุณสร้างอะไรด้วยสิ่งนี้ เราอยากเห็น พบเราได้ที่ @pixtopia บน Pixa