|
1 | | -import { Code } from "nextra/components"; |
| 1 | +import { Code, Tabs, Callout } from "nextra/components"; |
2 | 2 |
|
3 | 3 | import { bridgedChains, stages, mainStageId } from "../../../../data/stages"; |
4 | 4 | import { MDX } from "../../../../components/mdx"; |
@@ -48,7 +48,136 @@ the <DataLink link="biomapperSdkDocs">Biomapper SDK Docs</DataLink>. |
48 | 48 |
|
49 | 49 | Integrating on the frontend is as simple as adding a link to the Biomapper App. |
50 | 50 |
|
51 | | -In general, you can always find the right URL at the [contract addresses] page. |
| 51 | +<Callout type="info"> |
| 52 | + Ignoring [generations](/generations) could lead to Sybil attacks. |
| 53 | +</Callout> |
| 54 | + |
| 55 | +Here is an example of how to check if a wallet is biomapped in the last generation |
| 56 | +known to Biomapper on {props.bridgedChain.generalDisplayName}. |
| 57 | + |
| 58 | +#### Get contract ABI |
| 59 | + |
| 60 | +The proper way is to create ABI from `IBridgedBiomapperRead` interface in `@biomapper-sdk/core`. |
| 61 | + |
| 62 | +Alternatively you can use these 2 functions: |
| 63 | + |
| 64 | +<Tabs |
| 65 | + storageKey="web3lib" |
| 66 | + items={['Viem', 'Ethers v6']}> |
| 67 | +> |
| 68 | + <Tabs.Tab> |
| 69 | + ```ts |
| 70 | + const biomapperAbi = parseAbi([ |
| 71 | + "function generationsHead() external view returns (uint256)", |
| 72 | + "function lookupBiomappingPtr(address account, uint256 generationPtr) external view returns (uint256)", |
| 73 | + ]); |
| 74 | + ``` |
| 75 | + |
| 76 | + </Tabs.Tab> |
| 77 | + <Tabs.Tab> |
| 78 | + ```ts |
| 79 | + const biomapperAbi = [ |
| 80 | + "function generationsHead() external view returns (uint256)", |
| 81 | + "function lookupBiomappingPtr(address account, uint256 generationPtr) external view returns (uint256)", |
| 82 | + ]; |
| 83 | + ``` |
| 84 | + </Tabs.Tab> |
| 85 | +</Tabs> |
| 86 | + |
| 87 | +#### Get contract address |
| 88 | + |
| 89 | +Look up the [contract addresses] page for full contract addresses info. |
| 90 | + |
| 91 | +<If condition={stages[mainStageId].bridged[props.bridgedChainId] !== null}> |
| 92 | + |
| 93 | +For the Biomapper on {props.bridgedChain.generalDisplayName} Mainnet: |
| 94 | + |
| 95 | +{/* prettier-ignore */} |
| 96 | +<MDX.pre> |
| 97 | + <MDX.code> const biomapperContractAddress = '{stages[mainStageId].bridged[props.bridgedChainId]?.addresses.bridgedBiomapper}';</MDX.code> |
| 98 | +</MDX.pre> |
| 99 | + |
| 100 | +</If> |
| 101 | + |
| 102 | +For the Biomapper on {stages["testnet5"].bridged[props.bridgedChainId]?.displayName}: |
| 103 | + |
| 104 | +{/* prettier-ignore */} |
| 105 | +<MDX.pre> |
| 106 | + <MDX.code> const biomapperContractAddress = '{stages["testnet5"].bridged[props.bridgedChainId]?.addresses.bridgedBiomapper}';</MDX.code> |
| 107 | +</MDX.pre> |
| 108 | + |
| 109 | +#### Get current biomapping generation |
| 110 | + |
| 111 | +<Tabs |
| 112 | + storageKey="web3lib" |
| 113 | + items={['Viem', 'Ethers 6']}> |
| 114 | +> |
| 115 | + <Tabs.Tab> |
| 116 | + See more about `readContract` function on https://viem.sh/docs/contract/readContract. |
| 117 | + |
| 118 | + ```ts |
| 119 | + const lastKnownGeneration = await publicClient.readContract({ |
| 120 | + address: biomapperContractAddress, |
| 121 | + abi: biomapperAbi, |
| 122 | + functionName: "generationsHead", |
| 123 | + }); |
| 124 | + ``` |
| 125 | + |
| 126 | + </Tabs.Tab> |
| 127 | + <Tabs.Tab> |
| 128 | + See more about how to read Ethers contracts on https://docs.ethers.org/v6/getting-started/#cid_56. |
| 129 | + |
| 130 | + ```ts |
| 131 | + // Prepare re-usable contract definition. |
| 132 | + const biomapperContract = new Contract(biomapperContractAddress, biomapperAbi, provider); |
| 133 | + |
| 134 | + const lastKnownGeneration = await generationsHead(); |
| 135 | + |
| 136 | + ``` |
| 137 | + |
| 138 | + </Tabs.Tab> |
| 139 | +</Tabs> |
| 140 | + |
| 141 | +#### Get biomapping status in the last known generation |
| 142 | + |
| 143 | +To get biomapping status for some address `addressToCheck` in the last known generation |
| 144 | + |
| 145 | +<Tabs |
| 146 | + storageKey="web3lib" |
| 147 | + items={['Viem', 'Ethers 6']}> |
| 148 | +> |
| 149 | + <Tabs.Tab> |
| 150 | + ```ts |
| 151 | + const biomappingPtrInLastKnownGeneration = await publicClient.readContract({ |
| 152 | + address: biomapperContractAddress, |
| 153 | + abi: biomapperAbi, |
| 154 | + functionName: "lookupBiomappingPtr", |
| 155 | + args: [addressToCheck, lastKnownGeneration], |
| 156 | + }); |
| 157 | + ``` |
| 158 | + |
| 159 | + </Tabs.Tab> |
| 160 | + <Tabs.Tab> |
| 161 | + ```ts |
| 162 | + const biomappingPtrInLastKnownGeneration = |
| 163 | + await biomapperContract.lookupBiomappingPtr( |
| 164 | + addressToCheck, |
| 165 | + lastKnownGeneration |
| 166 | + ); |
| 167 | + |
| 168 | + ``` |
| 169 | + |
| 170 | + </Tabs.Tab> |
| 171 | +</Tabs> |
| 172 | + |
| 173 | +`biomappingPtrInLastKnownGeneration` is the block number on |
| 174 | +Humanode Testnet 5 <If condition={stages[mainStageId].bridged[props.bridgedChainId] !== null}>(or Humanode Mainnet) </If> |
| 175 | +of biomapping tx in the last known generation for specified address, |
| 176 | +or zero if such address is not biomapped. |
| 177 | + |
| 178 | +```ts |
| 179 | +const biomappingStatus = biomappingPtrInLastKnownGeneration !== 0n; |
| 180 | +``` |
52 | 181 |
|
53 | 182 | ## Rollout |
54 | 183 |
|
|
0 commit comments