mirror of
https://github.com/status-im/docs.status.network.git
synced 2026-08-31 10:31:10 +00:00
1 line
29 KiB
JavaScript
1 line
29 KiB
JavaScript
"use strict";(self.webpackChunkstatus_network_docs=self.webpackChunkstatus_network_docs||[]).push([[9397],{625:(e,n,a)=>{a.r(n),a.d(n,{assets:()=>u,contentTitle:()=>c,default:()=>h,frontMatter:()=>l,metadata:()=>r,toc:()=>d});const r=JSON.parse('{"id":"build-for-karma/guides/reputation-integration","title":"\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u7d71\u5408\u30ac\u30a4\u30c9","description":"Status Network\u3067Karma\u30c6\u30a3\u30a2\u3092\u8aad\u307f\u53d6\u308a\u3001\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u6a5f\u80fd\u3092\u30b2\u30fc\u30c6\u30a3\u30f3\u30b0\u3057\u3001Karma\u5bfe\u5fdc\u306e\u30b9\u30de\u30fc\u30c8\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u3068\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3092\u69cb\u7bc9\u3059\u308b\u65b9\u6cd5\u3002","source":"@site/i18n/ja/docusaurus-plugin-content-docs/current/build-for-karma/guides/reputation-integration.md","sourceDirName":"build-for-karma/guides","slug":"/build-for-karma/guides/reputation-integration","permalink":"/ja/build-for-karma/guides/reputation-integration","draft":false,"unlisted":false,"editUrl":"https://github.com/status-im/docs.status.network/tree/develop/docs/build-for-karma/guides/reputation-integration.md","tags":[],"version":"current","lastUpdatedAt":1776159652000,"sidebarPosition":4,"frontMatter":{"title":"\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u7d71\u5408\u30ac\u30a4\u30c9","description":"Status Network\u3067Karma\u30c6\u30a3\u30a2\u3092\u8aad\u307f\u53d6\u308a\u3001\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u6a5f\u80fd\u3092\u30b2\u30fc\u30c6\u30a3\u30f3\u30b0\u3057\u3001Karma\u5bfe\u5fdc\u306e\u30b9\u30de\u30fc\u30c8\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u3068\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3092\u69cb\u7bc9\u3059\u308b\u65b9\u6cd5\u3002","keywords":["Karma","\u30a4\u30f3\u30c6\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3","\u30b9\u30de\u30fc\u30c8\u30b3\u30f3\u30c8\u30e9\u30af\u30c8","\u30bd\u30a6\u30eb\u30d0\u30a6\u30f3\u30c9\u30c8\u30fc\u30af\u30f3","\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3","\u30c6\u30a3\u30a2","\u30ac\u30b9\u30ec\u30b9","Status Network","\u958b\u767a\u8005\u30ac\u30a4\u30c9"],"slug":"/build-for-karma/guides/reputation-integration","sidebar_position":4},"sidebar":"buildForKarmaSidebar","previous":{"title":"\u26fd Gasless Integration","permalink":"/ja/build-for-karma/guides/gasless-integration"},"next":{"title":"\u6700\u521d\u306e\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u3092\u30c7\u30d7\u30ed\u30a4\u3059\u308b","permalink":"/ja/build-for-karma/deploying-contracts"}}');var t=a(4848),i=a(8453),s=a(1470),o=a(9365);const l={title:"\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u7d71\u5408\u30ac\u30a4\u30c9",description:"Status Network\u3067Karma\u30c6\u30a3\u30a2\u3092\u8aad\u307f\u53d6\u308a\u3001\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u6a5f\u80fd\u3092\u30b2\u30fc\u30c6\u30a3\u30f3\u30b0\u3057\u3001Karma\u5bfe\u5fdc\u306e\u30b9\u30de\u30fc\u30c8\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u3068\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3092\u69cb\u7bc9\u3059\u308b\u65b9\u6cd5\u3002",keywords:["Karma","\u30a4\u30f3\u30c6\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3","\u30b9\u30de\u30fc\u30c8\u30b3\u30f3\u30c8\u30e9\u30af\u30c8","\u30bd\u30a6\u30eb\u30d0\u30a6\u30f3\u30c9\u30c8\u30fc\u30af\u30f3","\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3","\u30c6\u30a3\u30a2","\u30ac\u30b9\u30ec\u30b9","Status Network","\u958b\u767a\u8005\u30ac\u30a4\u30c9"],slug:"/build-for-karma/guides/reputation-integration",sidebar_position:4},c="\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u7d71\u5408\u30ac\u30a4\u30c9",u={},d=[{value:"\u30aa\u30f3\u30c1\u30a7\u30fc\u30f3\u3067\u306eKarma\u8aad\u307f\u53d6\u308a",id:"\u30aa\u30f3\u30c1\u30a7\u30fc\u30f3\u3067\u306ekarma\u8aad\u307f\u53d6\u308a",level:2},{value:"\u8003\u3048\u3089\u308c\u308b\u7d71\u5408\u30d1\u30bf\u30fc\u30f3",id:"\u8003\u3048\u3089\u308c\u308b\u7d71\u5408\u30d1\u30bf\u30fc\u30f3",level:2},{value:"\u6a5f\u80fd\u30b2\u30fc\u30c6\u30a3\u30f3\u30b0",id:"\u6a5f\u80fd\u30b2\u30fc\u30c6\u30a3\u30f3\u30b0",level:3},{value:"\u30c0\u30a4\u30ca\u30df\u30c3\u30af\u30d7\u30e9\u30a4\u30b7\u30f3\u30b0",id:"\u30c0\u30a4\u30ca\u30df\u30c3\u30af\u30d7\u30e9\u30a4\u30b7\u30f3\u30b0",level:3},{value:"\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u8868\u793a",id:"\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u8868\u793a",level:3},{value:"\u52a0\u91cd\u30ac\u30d0\u30ca\u30f3\u30b9",id:"\u52a0\u91cd\u30ac\u30d0\u30ca\u30f3\u30b9",level:3},{value:"\u6b21\u306e\u30b9\u30c6\u30c3\u30d7",id:"\u6b21\u306e\u30b9\u30c6\u30c3\u30d7",level:2}];function m(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.header,{children:(0,t.jsx)(n.h1,{id:"\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u7d71\u5408\u30ac\u30a4\u30c9",children:"\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u7d71\u5408\u30ac\u30a4\u30c9"})}),"\n",(0,t.jsx)(n.p,{children:"Karma\u306fStatus Network\u306e\u30bd\u30a6\u30eb\u30d0\u30a6\u30f3\u30c9\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u30c8\u30fc\u30af\u30f3\u3067\u3059\u3002\u3059\u3079\u3066\u306e\u30a2\u30c9\u30ec\u30b9\u306f\u3001SNT\u30b9\u30c6\u30fc\u30ad\u30f3\u30b0\u3001\u30a2\u30bb\u30c3\u30c8\u306e\u30d6\u30ea\u30c3\u30b8\u3001\u6d41\u52d5\u6027\u63d0\u4f9b\u3001\u30a2\u30d7\u30ea\u306e\u4f7f\u7528\u3001\u30d7\u30ec\u30df\u30a2\u30e0\u30ac\u30b9\u624b\u6570\u6599\u306e\u652f\u6255\u3044\u306a\u3069\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3078\u306e\u771f\u6b63\u306a\u53c2\u52a0\u3092\u901a\u3058\u3066Karma\u3092\u7372\u5f97\u3057\u307e\u3059\u3002Karma\u306f\u8cfc\u5165\u3001\u58f2\u5374\u3001\u8ee2\u9001\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002"}),"\n",(0,t.jsx)(n.p,{children:"\u3053\u306e\u30ac\u30a4\u30c9\u3067\u306f\u3001Karma\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u53d6\u308a\u65b9\u6cd5\u3068\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u30c6\u30a3\u30a2\u306b\u5fdc\u3058\u305f\u30a2\u30d7\u30ea\u306e\u69cb\u7bc9\u65b9\u6cd5\u3092\u8aac\u660e\u3057\u307e\u3059\u3002"}),"\n",(0,t.jsx)(n.h2,{id:"\u30aa\u30f3\u30c1\u30a7\u30fc\u30f3\u3067\u306ekarma\u8aad\u307f\u53d6\u308a",children:"\u30aa\u30f3\u30c1\u30a7\u30fc\u30f3\u3067\u306eKarma\u8aad\u307f\u53d6\u308a"}),"\n",(0,t.jsx)(n.p,{children:"Karma\u306e\u72b6\u614b\u306f2\u3064\u306e\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306b\u5206\u304b\u308c\u3066\u3044\u307e\u3059:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.strong,{children:"Karma"})," \u2014 \u30bd\u30a6\u30eb\u30d0\u30a6\u30f3\u30c9ERC-20\u30c8\u30fc\u30af\u30f3\u3002",(0,t.jsx)(n.code,{children:"balanceOf"}),"\u306f\u30b9\u30e9\u30c3\u30b7\u30f3\u30b0\u5f8c\u306e\u7d14\u6b8b\u9ad8\u3092\u8fd4\u3057\u307e\u3059\u3002\u8ee2\u9001\u3068\u627f\u8a8d\u306f\u5e38\u306b\u30ea\u30d0\u30fc\u30c8\u3057\u307e\u3059\u3002"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.strong,{children:"KarmaTiers"})," \u2014 \u6b8b\u9ad8\u3092\u30c6\u30a3\u30a2\u306b\u30de\u30c3\u30d4\u30f3\u30b0\u3057\u307e\u3059\u3002",(0,t.jsx)(n.code,{children:"getTierIdByKarmaBalance(balance)"}),"\u3092\u547c\u3073\u51fa\u3057\u3066\u304b\u3089",(0,t.jsx)(n.code,{children:"getTierById(tierId)"}),"\u3092\u547c\u3073\u51fa\u3057\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u30c6\u30a3\u30a2\u3068\u305d\u306e",(0,t.jsx)(n.code,{children:"txPerEpoch"}),"\u30af\u30a9\u30fc\u30bf\u3092\u89e3\u6c7a\u3057\u307e\u3059\u3002"]}),"\n"]}),"\n",(0,t.jsxs)(s.A,{groupId:"karma-reading",children:[(0,t.jsx)(o.A,{value:"solidity",label:"Solidity",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-solidity",children:'// SPDX-License-Identifier: MIT\npragma solidity 0.8.26;\n\n/// @notice Minimal interface for the Karma soulbound token.\ninterface IKarma {\n /// @notice Net Karma balance of `account` after slashing.\n function balanceOf(address account) external view returns (uint256);\n\n /// @notice Total amount slashed from `account` across all distributors.\n function slashedAmountOf(address account) external view returns (uint256);\n}\n\n/// @notice Minimal interface for the KarmaTiers registry.\ninterface IKarmaTiers {\n struct Tier {\n uint256 minKarma;\n uint256 maxKarma;\n string name;\n uint32 txPerEpoch; // gasless transactions allowed per epoch\n }\n\n /// @notice Returns the highest tier ID the given karma balance qualifies for.\n function getTierIdByKarmaBalance(uint256 karmaBalance) external view returns (uint8);\n\n /// @notice Returns the full Tier struct for a given tier ID.\n function getTierById(uint8 tierId) external view returns (Tier memory);\n\n /// @notice Returns the total number of configured tiers.\n function getTierCount() external view returns (uint256);\n}\n\ncontract KarmaGated {\n IKarma public karma;\n IKarmaTiers public karmaTiers;\n\n constructor(address _karmaContract, address _karmaTiersContract) {\n karma = IKarma(_karmaContract);\n karmaTiers = IKarmaTiers(_karmaTiersContract);\n }\n\n /// @notice Resolves the tier ID for `user` from their current Karma balance.\n function tierIdOf(address user) public view returns (uint8) {\n return karmaTiers.getTierIdByKarmaBalance(karma.balanceOf(user));\n }\n\n modifier onlyTier(uint8 minTier) {\n require(tierIdOf(msg.sender) >= minTier, "Karma tier too low");\n _;\n }\n\n function premiumAction() external onlyTier(3) {\n // Only users at tier 3 or above can call this\n }\n\n function getDiscount(address user) external view returns (uint256) {\n uint8 tierId = tierIdOf(user);\n // Higher tiers get bigger discounts\n return uint256(tierId) * 5; // 0%, 5%, 10%, ...\n }\n}\n'})})}),(0,t.jsx)(o.A,{value:"ethers",label:"ethers.js",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"import { ethers } from 'ethers';\n\nconst provider = new ethers.JsonRpcProvider(\n 'https://public.hoodi.rpc.status.network'\n);\n\nconst KARMA_ABI = [\n 'function balanceOf(address account) view returns (uint256)',\n 'function slashedAmountOf(address account) view returns (uint256)',\n];\n\nconst KARMA_TIERS_ABI = [\n 'function getTierIdByKarmaBalance(uint256 karmaBalance) view returns (uint8)',\n 'function getTierById(uint8 tierId) view returns (tuple(uint256 minKarma, uint256 maxKarma, string name, uint32 txPerEpoch))',\n 'function getTierCount() view returns (uint256)',\n];\n\nconst karma = new ethers.Contract(KARMA_ADDRESS, KARMA_ABI, provider);\nconst karmaTiers = new ethers.Contract(KARMA_TIERS_ADDRESS, KARMA_TIERS_ABI, provider);\n\n// \u30e6\u30fc\u30b6\u30fc\u306eKarma\u6b8b\u9ad8\u3092\u8aad\u307f\u53d6\u308a\u3001\u30c6\u30a3\u30a2\u3092\u89e3\u6c7a\nconst balance = await karma.balanceOf(userAddress);\nconst tierId = await karmaTiers.getTierIdByKarmaBalance(balance);\nconst tier = await karmaTiers.getTierById(tierId);\n\nconsole.log(`Karma\u6b8b\u9ad8: ${ethers.formatEther(balance)} KARMA`);\nconsole.log(`\u30c6\u30a3\u30a2: ${tier.name} (ID ${tierId})`);\nconsole.log(`\u30a8\u30dd\u30c3\u30af\u3042\u305f\u308a\u306eTx: ${tier.txPerEpoch}`);\n"})})}),(0,t.jsx)(o.A,{value:"viem",label:"viem",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import { createPublicClient, http } from 'viem';\n\nconst client = createPublicClient({\n transport: http('https://public.hoodi.rpc.status.network'),\n});\n\nconst karmaAbi = [\n {\n name: 'balanceOf',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'account', type: 'address' }],\n outputs: [{ name: '', type: 'uint256' }],\n },\n {\n name: 'slashedAmountOf',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'account', type: 'address' }],\n outputs: [{ name: '', type: 'uint256' }],\n },\n] as const;\n\nconst karmaTiersAbi = [\n {\n name: 'getTierIdByKarmaBalance',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'karmaBalance', type: 'uint256' }],\n outputs: [{ name: '', type: 'uint8' }],\n },\n {\n name: 'getTierById',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'tierId', type: 'uint8' }],\n outputs: [{\n name: 'tier',\n type: 'tuple',\n components: [\n { name: 'minKarma', type: 'uint256' },\n { name: 'maxKarma', type: 'uint256' },\n { name: 'name', type: 'string' },\n { name: 'txPerEpoch', type: 'uint32' },\n ],\n }],\n },\n] as const;\n\n// 2\u56de\u306e\u9806\u6b21\u8aad\u307f\u53d6\u308a: \u6b8b\u9ad8 \u2192 \u30c6\u30a3\u30a2ID \u2192 \u30c6\u30a3\u30a2\u8a73\u7d30\nconst balance = await client.readContract({\n address: KARMA_ADDRESS,\n abi: karmaAbi,\n functionName: 'balanceOf',\n args: [userAddress],\n});\n\nconst tierId = await client.readContract({\n address: KARMA_TIERS_ADDRESS,\n abi: karmaTiersAbi,\n functionName: 'getTierIdByKarmaBalance',\n args: [balance],\n});\n\nconst tier = await client.readContract({\n address: KARMA_TIERS_ADDRESS,\n abi: karmaTiersAbi,\n functionName: 'getTierById',\n args: [tierId],\n});\n\nconsole.log(`\u30c6\u30a3\u30a2: ${tier.name} (ID ${tierId})`);\nconsole.log(`\u30a8\u30dd\u30c3\u30af\u3042\u305f\u308a\u306eTx: ${tier.txPerEpoch}`);\n"})})})]}),"\n",(0,t.jsx)(n.admonition,{title:"\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u30a2\u30c9\u30ec\u30b9",type:"note",children:(0,t.jsxs)(n.p,{children:["Karma\u3068KarmaTiers\u306e\u30c6\u30b9\u30c8\u30cd\u30c3\u30c8\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u30a2\u30c9\u30ec\u30b9\u306f",(0,t.jsx)(n.a,{href:"/overview/general-info/contract-addresses/testnet-contracts",children:"\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u30a2\u30c9\u30ec\u30b9"}),"\u30da\u30fc\u30b8\u306b\u63b2\u8f09\u3055\u308c\u3066\u3044\u307e\u3059\u3002"]})}),"\n",(0,t.jsx)(n.h2,{id:"\u8003\u3048\u3089\u308c\u308b\u7d71\u5408\u30d1\u30bf\u30fc\u30f3",children:"\u8003\u3048\u3089\u308c\u308b\u7d71\u5408\u30d1\u30bf\u30fc\u30f3"}),"\n",(0,t.jsx)(n.h3,{id:"\u6a5f\u80fd\u30b2\u30fc\u30c6\u30a3\u30f3\u30b0",children:"\u6a5f\u80fd\u30b2\u30fc\u30c6\u30a3\u30f3\u30b0"}),"\n",(0,t.jsxs)(n.p,{children:["Karma\u30c6\u30a3\u30a2\u306b\u57fa\u3065\u3044\u3066\u6a5f\u80fd\u3092\u30a2\u30f3\u30ed\u30c3\u30af\u3057\u307e\u3059\u3002",(0,t.jsx)(n.a,{href:"#%E3%82%AA%E3%83%B3%E3%83%81%E3%82%A7%E3%83%BC%E3%83%B3%E3%81%A7%E3%81%AEkarma%E8%AA%AD%E3%81%BF%E5%8F%96%E3%82%8A",children:"\u30aa\u30f3\u30c1\u30a7\u30fc\u30f3\u3067\u306eKarma\u8aad\u307f\u53d6\u308a"}),"\u30bb\u30af\u30b7\u30e7\u30f3\u306e",(0,t.jsx)(n.code,{children:"onlyTier"}),"\u30e2\u30c7\u30a3\u30d5\u30a1\u30a4\u30a2\u304c\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u30ec\u30d9\u30eb\u3067\u30a2\u30af\u30bb\u30b9\u3092\u5236\u5fa1\u3057\u307e\u3059:"]}),"\n",(0,t.jsxs)(s.A,{groupId:"karma-gating",children:[(0,t.jsx)(o.A,{value:"solidity",label:"Solidity",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-solidity",children:"function accessPremiumContent() external onlyTier(3) {\n // Only users at tier 3 or above can call this\n}\n"})})}),(0,t.jsx)(o.A,{value:"ethers",label:"ethers.js",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"// Karma\u6b8b\u9ad8\u304b\u3089\u30c6\u30a3\u30a2\u3092\u89e3\u6c7a\u3057\u3001UI\u6a5f\u80fd\u3092\u30b2\u30fc\u30c6\u30a3\u30f3\u30b0\nconst balance = await karma.balanceOf(userAddress);\nconst tierId = await karmaTiers.getTierIdByKarmaBalance(balance);\n\nif (tierId >= 3) {\n showPremiumFeatures();\n} else {\n showUpgradePrompt(tierId);\n}\n"})})}),(0,t.jsx)(o.A,{value:"viem",label:"viem",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"const balance = await client.readContract({\n address: KARMA_ADDRESS,\n abi: karmaAbi,\n functionName: 'balanceOf',\n args: [userAddress],\n});\n\nconst tierId = await client.readContract({\n address: KARMA_TIERS_ADDRESS,\n abi: karmaTiersAbi,\n functionName: 'getTierIdByKarmaBalance',\n args: [balance],\n});\n\nif (tierId >= 3) {\n showPremiumFeatures();\n} else {\n showUpgradePrompt(tierId);\n}\n"})})})]}),"\n",(0,t.jsx)(n.h3,{id:"\u30c0\u30a4\u30ca\u30df\u30c3\u30af\u30d7\u30e9\u30a4\u30b7\u30f3\u30b0",children:"\u30c0\u30a4\u30ca\u30df\u30c3\u30af\u30d7\u30e9\u30a4\u30b7\u30f3\u30b0"}),"\n",(0,t.jsx)(n.p,{children:"\u9ad8Karma\u30e6\u30fc\u30b6\u30fc\u306b\u5272\u5f15\u3084\u3088\u308a\u826f\u3044\u30ec\u30fc\u30c8\u3092\u63d0\u4f9b\u3057\u307e\u3059:"}),"\n",(0,t.jsxs)(s.A,{groupId:"karma-pricing",children:[(0,t.jsx)(o.A,{value:"solidity",label:"Solidity",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-solidity",children:"function calculateFee(address user, uint256 baseAmount) public view returns (uint256) {\n uint8 tierId = karmaTiers.getTierIdByKarmaBalance(karma.balanceOf(user));\n // Each tier gives 5% discount\n uint256 discount = uint256(tierId) * 5;\n return baseAmount * (100 - discount) / 100;\n}\n"})})}),(0,t.jsx)(o.A,{value:"ethers",label:"ethers.js",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"// \u30e6\u30fc\u30b6\u30fc\u306e\u73fe\u5728\u306e\u30c6\u30a3\u30a2\u304b\u3089\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u3067\u5272\u5f15\u624b\u6570\u6599\u3092\u8a08\u7b97\nconst balance = await karma.balanceOf(userAddress);\nconst tierId = await karmaTiers.getTierIdByKarmaBalance(balance);\n\nconst discount = BigInt(tierId) * 5n; // \u30c6\u30a3\u30a2\u3054\u3068\u306b5%\u5272\u5f15\nconst fee = baseAmount * (100n - discount) / 100n;\n\nconsole.log(`\u30c6\u30a3\u30a2 ${tierId}: ${discount}% \u5272\u5f15 \u2192 \u624b\u6570\u6599 = ${fee}`);\n"})})}),(0,t.jsx)(o.A,{value:"viem",label:"viem",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"const balance = await client.readContract({\n address: KARMA_ADDRESS,\n abi: karmaAbi,\n functionName: 'balanceOf',\n args: [userAddress],\n});\n\nconst tierId = await client.readContract({\n address: KARMA_TIERS_ADDRESS,\n abi: karmaTiersAbi,\n functionName: 'getTierIdByKarmaBalance',\n args: [balance],\n});\n\nconst discount = BigInt(tierId) * 5n; // \u30c6\u30a3\u30a2\u3054\u3068\u306b5%\u5272\u5f15\nconst fee = baseAmount * (100n - discount) / 100n;\n\nconsole.log(`\u30c6\u30a3\u30a2 ${tierId}: ${discount}% \u5272\u5f15 \u2192 \u624b\u6570\u6599 = ${fee}`);\n"})})})]}),"\n",(0,t.jsx)(n.h3,{id:"\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u8868\u793a",children:"\u30ec\u30d4\u30e5\u30c6\u30fc\u30b7\u30e7\u30f3\u8868\u793a"}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"KarmaTiers"}),"\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u304b\u3089\u76f4\u63a5\u540d\u524d\u3092\u8aad\u307f\u53d6\u3063\u3066\u3001UI\u306bKarma\u30c6\u30a3\u30a2\u3092\u4fe1\u983c\u30b7\u30b0\u30ca\u30eb\u3068\u3057\u3066\u8868\u793a\u3057\u307e\u3059:"]}),"\n",(0,t.jsxs)(s.A,{groupId:"karma-display",children:[(0,t.jsx)(o.A,{value:"ethers",label:"ethers.js",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:'// \u30aa\u30f3\u30c1\u30a7\u30fc\u30f3\u3067\u30c6\u30a3\u30a2\u540d\u3092\u53d6\u5f97 \u2014 \u30cf\u30fc\u30c9\u30b3\u30fc\u30c9\u3055\u308c\u305f\u914d\u5217\u306f\u4e0d\u8981\nconst balance = await karma.balanceOf(userAddress);\nconst tierId = await karmaTiers.getTierIdByKarmaBalance(balance);\nconst tier = await karmaTiers.getTierById(tierId);\n\nfunction KarmaBadge({ tierName }) {\n return <span className="karma-badge">{tierName}</span>;\n}\n\n// \u4f7f\u7528\u65b9\u6cd5\n<KarmaBadge tierName={tier.name} />\n'})})}),(0,t.jsx)(o.A,{value:"viem",label:"viem",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"const balance = await client.readContract({\n address: KARMA_ADDRESS,\n abi: karmaAbi,\n functionName: 'balanceOf',\n args: [userAddress],\n});\n\nconst tierId = await client.readContract({\n address: KARMA_TIERS_ADDRESS,\n abi: karmaTiersAbi,\n functionName: 'getTierIdByKarmaBalance',\n args: [balance],\n});\n\nconst tier = await client.readContract({\n address: KARMA_TIERS_ADDRESS,\n abi: karmaTiersAbi,\n functionName: 'getTierById',\n args: [tierId],\n});\n\nfunction KarmaBadge({ tierName }: { tierName: string }) {\n return <span className=\"karma-badge\">{tierName}</span>;\n}\n\n// \u4f7f\u7528\u65b9\u6cd5\n<KarmaBadge tierName={tier.name} />\n"})})})]}),"\n",(0,t.jsx)(n.h3,{id:"\u52a0\u91cd\u30ac\u30d0\u30ca\u30f3\u30b9",children:"\u52a0\u91cd\u30ac\u30d0\u30ca\u30f3\u30b9"}),"\n",(0,t.jsx)(n.p,{children:"\u30a2\u30d7\u30ea\u306e\u30ac\u30d0\u30ca\u30f3\u30b9\u3067Karma\u3092\u6295\u7968\u306e\u91cd\u307f\u4ed8\u3051\u306b\u4f7f\u7528\u3057\u307e\u3059:"}),"\n",(0,t.jsxs)(s.A,{groupId:"karma-governance",children:[(0,t.jsx)(o.A,{value:"solidity",label:"Solidity",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-solidity",children:"function vote(uint256 proposalId, bool support) external {\n uint256 weight = karma.balanceOf(msg.sender);\n proposals[proposalId].votes += support ? int256(weight) : -int256(weight);\n}\n"})})}),(0,t.jsx)(o.A,{value:"ethers",label:"ethers.js",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"// \u30e6\u30fc\u30b6\u30fc\u306eKarma\u6b8b\u9ad8\u3092\u6295\u7968\u306e\u91cd\u307f\u3068\u3057\u3066\u8aad\u307f\u53d6\u308a\u3001\u9001\u4fe1\nconst weight = await karma.balanceOf(userAddress);\nconsole.log(`\u6295\u7968\u306e\u91cd\u307f: ${ethers.formatEther(weight)} KARMA`);\n\n// \u30ac\u30d0\u30ca\u30f3\u30b9\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u3092\u547c\u3073\u51fa\u3057\nconst tx = await governanceContract.vote(proposalId, support);\nawait tx.wait();\n"})})}),(0,t.jsx)(o.A,{value:"viem",label:"viem",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import { formatEther, parseAbi } from 'viem';\n\n// Karma\u6b8b\u9ad8\u304b\u3089\u6295\u7968\u306e\u91cd\u307f\u3092\u8aad\u307f\u53d6\u308a\nconst weight = await client.readContract({\n address: KARMA_ADDRESS,\n abi: karmaAbi,\n functionName: 'balanceOf',\n args: [userAddress],\n});\nconsole.log(`\u6295\u7968\u306e\u91cd\u307f: ${formatEther(weight)} KARMA`);\n\n// \u30ac\u30d0\u30ca\u30f3\u30b9\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u3092\u901a\u3058\u3066\u6295\u7968\u3092\u9001\u4fe1\nconst { request } = await client.simulateContract({\n address: GOVERNANCE_ADDRESS,\n abi: parseAbi(['function vote(uint256 proposalId, bool support) external']),\n functionName: 'vote',\n args: [proposalId, support],\n account: userAddress,\n});\nawait walletClient.writeContract(request);\n"})})})]}),"\n",(0,t.jsx)(n.h2,{id:"\u6b21\u306e\u30b9\u30c6\u30c3\u30d7",children:"\u6b21\u306e\u30b9\u30c6\u30c3\u30d7"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.a,{href:"/build-for-karma/guides/gasless-integration",children:"\u30ac\u30b9\u30ec\u30b9\u7d71\u5408"}),"\u3092\u53c2\u7167\u3057\u3066\u3001\u30ac\u30b9\u30ec\u30b9\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u306bKarma\u3092\u7d71\u5408\u3059\u308b\u65b9\u6cd5\u3092\u5b66\u3076"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.a,{href:"/overview/tokenomics/karmic-tokenomics",children:"\u30ab\u30eb\u30df\u30c3\u30af\u30c8\u30fc\u30af\u30ce\u30df\u30af\u30b9"}),"\u3067Karma\u306e\u7372\u5f97\u3068\u4f7f\u7528\u306e\u4ed5\u7d44\u307f\u3092\u78ba\u8a8d\u3059\u308b"]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.a,{href:"/overview/general-info/gasless-transactions",children:"\u30ac\u30b9\u30ec\u30b9\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3"}),"\u3067RLN\u30d9\u30fc\u30b9\u306e\u30ac\u30b9\u30ec\u30b9\u30b7\u30b9\u30c6\u30e0\u306e\u6280\u8853\u7684\u8a73\u7d30\u3092\u7406\u89e3\u3059\u308b"]}),"\n"]})]})}function h(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(m,{...e})}):m(e)}},1470:(e,n,a)=>{a.d(n,{A:()=>w});var r=a(6540),t=a(4164),i=a(7559),s=a(3104),o=a(6347),l=a(205),c=a(7485),u=a(1682),d=a(679);function m(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:n,children:a}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return m(e).map((({props:{value:e,label:n,attributes:a,default:r}})=>({value:e,label:n,attributes:a,default:r})))}(a);return function(e){const n=(0,u.XI)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(e),e}),[n,a])}function p({value:e,tabValues:n}){return n.some((n=>n.value===e))}function b({queryString:e=!1,groupId:n}){const a=(0,o.W6)(),t=function({queryString:e=!1,groupId:n}){if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!n)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:e,groupId:n});return[(0,c.aZ)(t),(0,r.useCallback)((e=>{if(!t)return;const n=new URLSearchParams(a.location.search);n.set(t,e),a.replace({...a.location,search:n.toString()})}),[t,a])]}function g(e){const{defaultValue:n,queryString:a=!1,groupId:t}=e,i=h(e),[s,o]=(0,r.useState)((()=>function({defaultValue:e,tabValues:n}){if(0===n.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(e){if(!p({value:e,tabValues:n}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:n,tabValues:i}))),[c,u]=b({queryString:a,groupId:t}),[m,g]=function({groupId:e}){const n=function(e){return e?`docusaurus.tab.${e}`:null}(e),[a,t]=(0,d.Dv)(n);return[a,(0,r.useCallback)((e=>{n&&t.set(e)}),[n,t])]}({groupId:t}),f=(()=>{const e=c??m;return p({value:e,tabValues:i})?e:null})();(0,l.A)((()=>{f&&o(f)}),[f]);return{selectedValue:s,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);o(e),u(e),g(e)}),[u,g,i]),tabValues:i}}var f=a(2303);const A={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=a(4848);function v({className:e,block:n,selectedValue:a,selectValue:r,tabValues:i}){const o=[],{blockElementScrollPositionUntilNextRender:l}=(0,s.a_)(),c=e=>{const n=e.currentTarget,t=o.indexOf(n),s=i[t].value;s!==a&&(l(n),r(s))},u=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const a=o.indexOf(e.currentTarget)+1;n=o[a]??o[0];break}case"ArrowLeft":{const a=o.indexOf(e.currentTarget)-1;n=o[a]??o[o.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,t.A)("tabs",{"tabs--block":n},e),children:i.map((({value:e,label:n,attributes:r})=>(0,x.jsx)("li",{role:"tab",tabIndex:a===e?0:-1,"aria-selected":a===e,ref:e=>{o.push(e)},onKeyDown:u,onClick:c,...r,className:(0,t.A)("tabs__item",A.tabItem,r?.className,{"tabs__item--active":a===e}),children:n??e},e)))})}function I({lazy:e,children:n,selectedValue:a}){const i=(Array.isArray(n)?n:[n]).filter(Boolean);if(e){const e=i.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:(0,t.A)("margin-top--md",e.props.className)}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:i.map(((e,n)=>(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==a})))})}function j(e){const n=g(e);return(0,x.jsxs)("div",{className:(0,t.A)(i.G.tabs.container,"tabs-container",A.tabList),children:[(0,x.jsx)(v,{...n,...e}),(0,x.jsx)(I,{...n,...e})]})}function w(e){const n=(0,f.A)();return(0,x.jsx)(j,{...e,children:m(e.children)},String(n))}},8453:(e,n,a)=>{a.d(n,{R:()=>s,x:()=>o});var r=a(6540);const t={},i=r.createContext(t);function s(e){const n=r.useContext(i);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:s(e.components),r.createElement(i.Provider,{value:n},e.children)}},9365:(e,n,a)=>{a.d(n,{A:()=>s});a(6540);var r=a(4164);const t={tabItem:"tabItem_Ymn6"};var i=a(4848);function s({children:e,hidden:n,className:a}){return(0,i.jsx)("div",{role:"tabpanel",className:(0,r.A)(t.tabItem,a),hidden:n,children:e})}}}]); |