diff --git a/src/app/integration/_meta.ts b/src/app/integration/_meta.ts index a334a2a..be58198 100644 --- a/src/app/integration/_meta.ts +++ b/src/app/integration/_meta.ts @@ -9,6 +9,8 @@ export default { href: links.biomapperSdkDocs, }, + humanode: "Humanode", + chains: { // This is not really a separator, it get overwritten by our hacks // at `pageMap.ts`. diff --git a/src/app/integration/chains/[bridgedChainId]/content.mdx b/src/app/integration/chains/[bridgedChainId]/content.mdx index 5e64378..07599bb 100644 --- a/src/app/integration/chains/[bridgedChainId]/content.mdx +++ b/src/app/integration/chains/[bridgedChainId]/content.mdx @@ -94,7 +94,7 @@ For the Biomapper on {props.bridgedChain.generalDisplayName} Mainnet: {/* prettier-ignore */} - const biomapperContractAddress = '{stages[mainStageId].bridged[props.bridgedChainId]?.addresses.bridgedBiomapper}'; + const biomapperContractAddress = "{stages[mainStageId].bridged[props.bridgedChainId]?.addresses.bridgedBiomapper}"; @@ -103,7 +103,7 @@ For the Biomapper on {stages["testnet5"].bridged[props.bridgedChainId]?.displayN {/* prettier-ignore */} - const biomapperContractAddress = '{stages["testnet5"].bridged[props.bridgedChainId]?.addresses.bridgedBiomapper}'; + const biomapperContractAddress = "{stages["testnet5"].bridged[props.bridgedChainId]?.addresses.bridgedBiomapper}"; #### Get current biomapping generation diff --git a/src/app/integration/humanode/page.mdx b/src/app/integration/humanode/page.mdx new file mode 100644 index 0000000..af128a4 --- /dev/null +++ b/src/app/integration/humanode/page.mdx @@ -0,0 +1,180 @@ +--- +title: Integrating with Humanode Biomapper on Humanode. +--- + +import { Tabs, Callout } from "nextra/components"; +import { stages } from "../../../data/stages"; +import { MDX } from "../../../components/mdx"; + +# Humanode + +Integrating with Humanode Biomapper on Humanode network. + + + Ignoring [generations](/generations) could lead to Sybil attacks. + + +This page describes integration with Biomapper on Humanode chain only. +To integrate with Biomapper on other chains check [Bridging page](/bridging) +and `Frontend` section of a [bridged chain](/#bridged-chains). + +## Simple Example + +Here is an example of how to check if a wallet is biomapped in the last generation +on Humanode Biomapper. + +### Get contract ABI + +The proper way is to create ABI from `IBiomapperLogRead` interface in `@biomapper-sdk/core`. + +Alternatively you can use these 2 functions: + + +> + + ```ts + const biomapperAbi = parseAbi([ + "function generationsHead() external view returns (uint256)", + "function generationBiomapping(address account, uint256 generationPtr) external view returns (uint256)", + ]); + ``` + + + + ```ts + const biomapperAbi = [ + "function generationsHead() external view returns (uint256)", + "function generationBiomapping(address account, uint256 generationPtr) external view returns (uint256)", + ]; + ``` + + + +### Get contract address + +Look up the [contract addresses](/contract-addresses) page for `BiomapperLog` contract address info. + +For the Biomapper on Humanode Mainnet: + +{/* prettier-ignore */} + + const biomapperContractAddress = "{stages.mainnet.humanode.addresses.biomapperLog}"; + + +For the Biomapper on Humanode Testnet 5: + +{/* prettier-ignore */} + + const biomapperContractAddress = "{stages.testnet5.humanode.addresses.biomapperLog}"; + + +### Get current biomapping generation + + +> + + See more about `readContract` function on https://viem.sh/docs/contract/readContract. + + ```ts + const lastGeneration = await publicClient.readContract({ + address: biomapperContractAddress, + abi: biomapperAbi, + functionName: "generationsHead", + }); + ``` + + + + See more about how to read Ethers contracts on https://docs.ethers.org/v6/getting-started/#cid_56. + + ```ts + // Prepare re-usable contract definition. + const biomapperContract = new Contract(biomapperContractAddress, biomapperAbi, provider); + + const lastGeneration = await biomapperContract.generationsHead(); + + ``` + + + + +### Get biomapping status in the last generation + +To get biomapping status for some address `addressToCheck` in the last generation + + +> + + ```ts + const biomappingPtrInLastGeneration = await publicClient.readContract({ + address: biomapperContractAddress, + abi: biomapperAbi, + functionName: "generationBiomapping", + args: [addressToCheck, lastGeneration], + }); + ``` + + + + ```ts + const biomappingPtrInLastGeneration = + await biomapperContract.generationBiomapping( + addressToCheck, + lastGeneration + ); + + ``` + + + + +`biomappingPtrInLastGeneration` is the block number on +Humanode Mainnet (or Humanode Testnet 5) +of biomapping tx in the last generation for specified address, +or zero if such address is not biomapped. + +```ts +const biomappingStatus = biomappingPtrInLastGeneration !== 0n; +``` + +## Alternative way + +To get biomapping status in an example above 2 functions are used: + +1. `generationsHead` to get block number of the last generation change tx; +2. `generationBiomapping` to get block number of biomapping tx in the last generation. + +The other way to get the status is: + +1. the same `generationsHead`; +2. `biomappingsHead` to get block number of the last biomapping tx for a specified account; +3. compare these block numbers. + +The ABI will be + +```json +[ + "function generationsHead() external view returns (uint256)", + "function biomappingsHead(address account) external view returns (uint256)" +] +``` + +In this case `biomappingStatus` will be calculated like this: + +```ts +const biomappingStatus = lastBiomapping > lastGeneration; +``` + +## Generations + +While this example can be helpful to show if the account is biomapped now, +in real dApps the generations should be taken into account. + +A restriction to a specific generation only could be sufficient +to prevent Sybil attacks.