พัฒนาด้วย PIXA Keychain

แอปส่งคำขอ ผู้ใช้อ่านในหน้าต่างของกระเป๋าเงิน และฟังก์ชันเรียกกลับได้รับคำตอบ คุณไม่เคยถือคีย์และไม่ต้องสมัครอะไร

กำลังค้นหา PIXA Keychain ในเบราว์เซอร์นี้

ค้นหากระเป๋าเงิน

ส่วนขยายเพิ่ม window.pixa_keychain ในทุกหน้าที่ใช้ https:// และใน localhost กับ 127.0.0.1 ขณะพัฒนา โดยจะปรากฏหลังหน้าโหลดแล้ว จึงควรรอสักครู่ก่อนบอกว่าไม่มี

ถ้าไม่มี ให้ลิงก์ไปที่ pixtopia.net/keychain ไม่ทำงานบนโทรศัพท์ จึงควรมีทางเข้าอื่นให้

JavaScript
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,
  });
});
บนเซิร์ฟเวอร์ของคุณ (Node)
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;
}

ลองที่นี่

นี่คือขั้นตอนเดียวกันที่ทำงานจริงบนหน้านี้ ลงนามข้อความทดสอบด้วยคีย์โพสต์ แล้วกู้คีย์จากลายเซ็นและค้นหาบนเชน ไม่มีการส่งธุรกรรม ไม่เก็บลายเซ็นหรือส่งไปที่ใด

ลงนามข้อความทดสอบ

ลงนามและส่ง

สำหรับการทำงานทั่วไป ขอสิ่งที่ต้องการแล้วกระเป๋าเงินจะสร้างธุรกรรม แสดงด้วยคำที่เข้าใจง่าย ลงนามและส่งผ่านโหนดของผู้ใช้

  • requestVote สำหรับถูกใจ น้ำหนักตั้งแต่ -10000 ถึง 10000
  • requestCustomJson สำหรับติดตามและข้อมูลของแอป แสดงข้อความ 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

ฟิลด์ความหมาย
successtrue ถ้าสำเร็จ
resultสิ่งที่คำขอสร้าง เช่น ลายเซ็นหรือผลการส่งธุรกรรม
errorเหตุผลที่ไม่สำเร็จ
messageประโยคที่คุณแสดงได้
dataคำขอตามที่กระเป๋าเงินได้รับ
publicKeyคีย์สาธารณะที่ลงนาม ถ้ามี
request_idหมายเลขคำขอนี้

ข้อผิดพลาดที่ควรจัดการ

user_cancelผู้ใช้ปฏิเสธ ไม่ต้องแจ้งอะไรเพิ่ม
incompleteคำขอไม่ถูกต้อง message บอกเหตุผล
ignoredคำขอใหม่กว่าจากหน้านี้แทนที่คำขอนี้
busyคำขอล่าสุดกำลังส่งแล้ว ให้รอ
ใช้ Promise ทีละคำขอ
// 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ตรวจว่ามีกระเป๋าเงินอยู่ ไม่เปิดหน้าต่าง
พารามิเตอร์ชนิดความหมาย
callbackfunctionยืนยันการติดตั้ง Keychain (ไม่มีพารามิเตอร์)
requestSignBufferลงนามข้อความ ซึ่งใช้ให้คนเข้าสู่ระบบ
พารามิเตอร์ชนิดความหมาย
account (ไม่บังคับ)Stringบัญชี Pixa ที่ทำคำขอ ถ้าเป็น null ผู้ใช้เลือกบัญชีจากรายการแบบเลื่อนลงได้
messageStringข้อความที่ให้บัญชีลงนาม
keyStringประเภทคีย์ ใช้ 'Posting','Active' หรือ 'Memo' ได้
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
rpc (ไม่บังคับ)Stringไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ
title (ไม่บังคับ)Stringไม่ใช้ กระเป๋าเงินเขียนหัวเรื่องเอง
requestVerifyKeyขอให้กระเป๋าเงินถอดรหัสข้อความเพื่อแสดงว่าถือคีย์อยู่
พารามิเตอร์ชนิดความหมาย
accountStringบัญชี Pixa ที่ทำคำขอ
messageStringข้อความที่ให้บัญชีถอดรหัส
keyStringประเภทคีย์ ใช้ 'Posting','Active' หรือ 'Memo' ได้
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
ตัวอย่าง
const keychain = window.pixa_keychain;
keychain.requestVerifyKey('pixtopia', encodedMessage, 'Posting', (response) => {
  if (response.success === true) {
    const decodedMessage = response.result;
  }
});
requestEncodeMessageเข้ารหัสข้อความให้อีกบัญชี
พารามิเตอร์ชนิดความหมาย
usernameStringบัญชี Pixa ที่ทำคำขอ
receiverStringบัญชีที่จะถอดรหัสสตริง
messageStringข้อความที่จะเข้ารหัส ต้องขึ้นต้นด้วย #
keyStringประเภทคีย์ ใช้ 'Posting','Active' หรือ 'Memo' ได้
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
ตัวอย่าง
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เข้ารหัสข้อความสำหรับคีย์สาธารณะหลายคีย์
พารามิเตอร์ชนิดความหมาย
usernameStringบัญชี Pixa ที่ทำคำขอ
publicKeysArray<String>คีย์ที่ถอดรหัสสตริงได้
messageStringข้อความที่จะเข้ารหัส ต้องขึ้นต้นด้วย #
keyStringประเภทคีย์ ใช้ 'Posting','Active' หรือ 'Memo' ได้
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
ตัวอย่าง
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เผยแพร่โพสต์หรือการตอบกลับ
พารามิเตอร์ชนิดความหมาย
accountStringบัญชี Pixa ที่ทำคำขอ
titleStringชื่อเรื่องโพสต์
bodyStringเนื้อหาโพสต์
parent_permStringPermlink ของโพสต์แม่ หรือแท็กหลักสำหรับโพสต์ระดับบนสุด
parent_accountStringผู้เขียนโพสต์แม่ ส่ง '' สำหรับโพสต์ระดับบนสุด
json_metadataStringข้อมูลเมตาของโพสต์ในรูป JSON
permlinkStringPermlink ของโพสต์
comment_optionsStringการตั้งค่ารางวัลโพสต์ในรูป JSON หรือ '' ต้องระบุผู้เขียนและ permlink นี้ และจะแสดงในการตรวจทาน
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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ถูกใจหรือดาวน์โหวตโพสต์
พารามิเตอร์ชนิดความหมาย
accountStringบัญชี Pixa ที่ทำคำขอ
permlinkStringPermlink ของโพสต์
authorStringผู้เขียนโพสต์
weightNumberน้ำหนักโหวตระหว่าง -10,000 (-100%) ถึง 10,000 (100%)
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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 ผู้ใช้เลือกบัญชีจากรายการแบบเลื่อนลงได้
idStringประเภท custom_json ที่จะส่ง
keyStringประเภทคีย์ ใช้ 'Posting' หรือ 'Active' ได้
jsonStringJSON แบบกำหนดเองที่แปลงเป็นสตริง
display_msgStringข้อความอธิบายให้ผู้ใช้ทราบว่าการส่งนี้เกี่ยวกับอะไร
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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ส่งการดำเนินการใด ๆ ในธุรกรรมเดียว
พารามิเตอร์ชนิดความหมาย
accountStringบัญชี Pixa ที่ทำคำขอ
operationsArrayอาร์เรย์การดำเนินการที่จะส่ง
keyStringประเภทคีย์ ใช้ 'Posting' หรือ 'Active' ได้
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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ลงนามธุรกรรมที่คุณเตรียม เพื่อให้คุณส่งเอง
พารามิเตอร์ชนิดความหมาย
accountStringบัญชี Pixa ที่ทำคำขอ
txObjectธุรกรรมที่ยังไม่ลงนาม
keyStringประเภทคีย์ ใช้ 'Posting' หรือ 'Active' ได้
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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
พารามิเตอร์ชนิดความหมาย
accountStringบัญชี Pixa ที่ทำคำขอ
toStringบัญชี Pixa ที่รับการโอน
amountStringจำนวนที่จะโอน ต้องมีทศนิยม 3 ตำแหน่ง
memoStringบันทึกจะเข้ารหัสอัตโนมัติถ้าขึ้นต้นด้วย '#' และมีคีย์บันทึกข้อความใน Keychain อีกทั้งจะบังคับบัญชีที่ใช้ ไม่ว่าพารามิเตอร์ 'enforce' จะเป็นอย่างไร
currencyString'PIXA' หรือ 'PXS'
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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 ที่ทำคำขอ
toStringบัญชี Pixa ที่รับการโอน
amountStringจำนวนที่ส่งแต่ละครั้ง
currencyStringPIXA หรือ PXS บนเครือข่ายหลัก
memoStringบันทึกการโอน
recurrenceNumberความถี่การจ่ายเป็นชั่วโมง อย่างน้อย 24
executionsNumberจำนวนครั้งที่จ่ายซ้ำ อย่างน้อย 2
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
rpc (ไม่บังคับ)Stringไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ
pair_id (ไม่บังคับ)NumberID คู่ของการโอนซ้ำ
ตัวอย่าง
// 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 เข้าออกเงินออม
พารามิเตอร์ชนิดความหมาย
usernameStringบัญชี Pixa ที่ทำคำขอ
toStringบัญชีที่รับการโอนเงินออม
amountStringจำนวนที่จะโอน ต้องมีทศนิยม 3 ตำแหน่ง
currencyString'PIXA' หรือ 'PXS'
operationString'deposit' หรือ 'withdraw'
memo (ไม่บังคับ)Stringบันทึกที่แนบกับการดำเนินการเงินออม
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
rpc (ไม่บังคับ)Stringไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ
ตัวอย่าง
const keychain = window.pixa_keychain;
keychain.requestSavingsOperation(username, toUsername, '1.000', 'PXS', 'deposit', 'test memo', (response) => {
  console.log(response);
});
requestConversionแปลงระหว่าง PXS และ PIXA
พารามิเตอร์ชนิดความหมาย
usernameStringบัญชี Pixa ที่ทำคำขอ
amountStringจำนวนที่จะแปลง
collaterizedBooleantrue เพื่อแปลง PIXA เป็น PXS และ false เพื่อแปลง PXS เป็น PIXA
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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
พารามิเตอร์ชนิดความหมาย
usernameStringบัญชี Pixa ที่ทำคำขอ
recipientStringบัญชีที่รับพลัง
hiveStringจำนวน PIXA ที่จะเพิ่มพลัง
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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
พารามิเตอร์ชนิดความหมาย
usernameStringบัญชี Pixa ที่ทำคำขอ
hive_powerStringจำนวน PIXA ที่จะถอนพลัง
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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 ผู้ใช้เลือกบัญชีจากรายการแบบเลื่อนลงได้
delegateeStringบัญชีที่รับการมอบหมาย
amountStringจำนวนที่จะโอน ต้องมีทศนิยม 3 ตำแหน่งสำหรับ PP และ 6 สำหรับ VESTS
unitStringPP หรือ VESTS
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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 ผู้ใช้เลือกบัญชีจากรายการแบบเลื่อนลงได้
witnessStringบัญชีที่รับโหวตพยาน
votebooleanตั้ง true เพื่อโหวตพยาน และ false เพื่อถอนโหวต
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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 ผู้ใช้เลือกบัญชีจากรายการแบบเลื่อนลงได้
proxyStringบัญชีที่จะเป็นผู้โหวตแทน ใช้สตริงว่าง ('') เพื่อลบผู้โหวตแทน
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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
พารามิเตอร์ชนิดความหมาย
usernameStringบัญชี Pixa ที่ทำคำขอ
receiverStringบัญชีที่รับเงินทุนหากข้อเสนอผ่านการโหวต
subjectStringชื่อข้อเสนอ
permlinkStringPermlink ไปยังคำอธิบายข้อเสนอ
daily_payStringจำนวนรายวันที่ receiver จะได้รับ เช่น '10.000 PXS'
startStringวันที่เริ่ม เช่น '2027-01-01T00:00:00'
endStringวันที่สิ้นสุดในรูปแบบเดียวกัน
extensionsStringอาร์เรย์ส่วนขยายที่แปลงเป็นสตริง
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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ลบข้อเสนอของบัญชีเอง
พารามิเตอร์ชนิดความหมาย
usernameStringบัญชี Pixa ที่ทำคำขอ
proposal_idsStringอาร์เรย์ ID ข้อเสนอที่จะลบ แปลงเป็นสตริง
extensionsStringอาร์เรย์ส่วนขยายที่แปลงเป็นสตริง
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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โหวตข้อเสนอหรือถอนโหวต
พารามิเตอร์ชนิดความหมาย
usernameStringบัญชี Pixa ที่ทำคำขอ
proposal_idsStringอาร์เรย์ ID ข้อเสนอที่จะโหวต แปลงเป็นสตริง
approvebooleanตั้ง true เพื่อสนับสนุนข้อเสนอ และ false เพื่อถอนโหวต
extensionsStringอาร์เรย์ส่วนขยายที่แปลงเป็นสตริง
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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เสนอให้เพิ่มคีย์บัญชีในกระเป๋าเงิน
พารามิเตอร์ชนิดความหมาย
usernameStringชื่อผู้ใช้ของบัญชีที่จะเพิ่ม
keysObjectคีย์ส่วนตัวของบัญชี: {active:'...',posting:'...',memo:'...'} ต้องระบุอย่างน้อยหนึ่งคีย์ หรือระบุบัญชีที่ได้รับสิทธิ์ด้วย @${username}
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
ตัวอย่าง
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สร้างบัญชีด้วยตั๋ว
พารามิเตอร์ชนิดความหมาย
usernameStringบัญชี Pixa ที่ทำคำขอ
new_accountStringบัญชีใหม่ที่จะสร้าง
ownerStringสิทธิ์เจ้าของในรูป JSON
activeStringสิทธิ์แอ็กทีฟในรูป JSON
postingStringสิทธิ์โพสต์ในรูป JSON
memoStringคีย์บันทึกข้อความสาธารณะ
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
rpc (ไม่บังคับ)Stringไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ
requestAddAccountAuthorityให้บัญชีอื่นมีสิทธิ์เหนือบัญชีนี้
พารามิเตอร์ชนิดความหมาย
accountStringบัญชี Pixa ที่ทำคำขอ
authorizedUsernameStringบัญชีที่ได้รับสิทธิ์
roleStringประเภทสิทธิ์ ใช้ 'Posting' หรือ 'Active' ได้
weightnumberน้ำหนักสิทธิ์
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
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ถอนสิทธิ์ของบัญชี
พารามิเตอร์ชนิดความหมาย
accountStringบัญชี Pixa ที่ทำคำขอ
authorizedUsernameStringบัญชีที่จะเสียสิทธิ์
roleStringประเภทสิทธิ์ ใช้ 'Posting' หรือ 'Active' ได้
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
rpc (ไม่บังคับ)Stringไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ
ตัวอย่าง
// Removes @pixtopia's active authority from `account`
const keychain = window.pixa_keychain;
keychain.requestRemoveAccountAuthority(account, 'pixtopia', 'Active', (response) => {
  console.log(response);
});
requestAddKeyAuthorityเพิ่มคีย์สาธารณะในสิทธิ์ของบัญชีนี้
พารามิเตอร์ชนิดความหมาย
accountStringบัญชี Pixa ที่ทำคำขอ
authorizedKeyStringคีย์สาธารณะใหม่ที่จะผูกกับบัญชี
roleStringประเภทสิทธิ์ ใช้ 'Posting' หรือ 'Active' ได้
weightnumberน้ำหนักสิทธิ์ของคีย์
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
rpc (ไม่บังคับ)Stringไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ
ตัวอย่าง
const keychain = window.pixa_keychain;
keychain.requestAddKeyAuthority(username, publicKey, 'Posting', 1, (response) => {
  console.log(response);
});
requestRemoveKeyAuthorityนำคีย์สาธารณะออกจากสิทธิ์ของบัญชีนี้
พารามิเตอร์ชนิดความหมาย
accountStringบัญชี Pixa ที่ทำคำขอ
authorizedKeyStringคีย์ที่จะลบ (คีย์สาธารณะ)
roleStringประเภทสิทธิ์ ใช้ 'Posting' หรือ 'Active' ได้
callbackfunctionฟังก์ชันที่จัดการคำตอบของกระเป๋าเงินต่อคำขอ
rpc (ไม่บังคับ)Stringไม่ใช้ กระเป๋าเงินใช้โหนดของผู้ใช้เสมอ
ตัวอย่าง
const keychain = window.pixa_keychain;
keychain.requestRemoveKeyAuthority(username, publicKey, 'Posting', (response) => {
  console.log(response);
});

ติดขัดหรือพบสิ่งที่ขาดไป?

เปิดประเด็นหรือส่งการแก้ไข ทุกอย่างอยู่บน GitHub ถ้าคุณสร้างอะไรด้วยสิ่งนี้ เราอยากเห็น พบเราได้ที่ @pixtopia บน Pixa