# Create Gnostic Conditional Token Positions using Scaffold Eth **Published by:** [tekh](https://paragraph.com/@quantumtekh/) **Published on:** 2023-08-28 **URL:** https://paragraph.com/@quantumtekh/create-gnostic-conditional-token-positions-using-scaffold-eth ## Content SummaryCreate Conditional Tokens Positions on Gnosis Chain using Scaffold-Eth 2. This document uses the Gnosis documentation “Introduction - Gnosis Developer Portal Conditional Tokens” as its source and will cover a limited Scope of the tutorial.Gnosis Developer Portal Conditional Tokens Tutorialhttps://docs.gnosis.io/conditionaltokens/docs/ctftutorial01/Scaffold-Eth 2https://scaffoldeth.io/ScopeRepositories and ModificationsDeploy Conditional and Collateral Token ContractsMint and Approve Collateral TokensConditional Token PreparationCreating Positions with Conditional TokensRepositories and ModificationsThe contract code was copied from the Gist repository in the gnosis tutorial and modified to support integration into scaffold-eth.Reference: Gnosis Developer Gist Repositoryhttps://gist.github.com/cag/65dc3ddfa03f067dd41ca7121ee3120fIn Use: Gnostic Condition Scaffold Eth Repositorygnostic-condition branch on OwlWilderness/se-2 repository This is the working repository for code in this demo. https://github.com/OwlWilderness/se-2/tree/gnostic-conditionConditional Token ContractThe import format was modified to use @Openzepplin instead of a github reference in all files. SafeMath was included for uint in the Conditional Tokens contract. https://github.com/OwlWilderness/se-2/blob/gnostic-condition/packages/hardhat/contracts/ConditionalTokens.sol//SPDX-License-Identifier: MIT pragma solidity >=0.8.0 <0.9.0; import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { ERC1155 } from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; import { CTHelpers } from "./CTHelpers.sol"; // Mainnet (ID: 1) canonical address: 0xC59b0e4De5F1248C1140964E0fF287B192407E0C // Rinkeby (ID: 4) canonical address: 0x36bede640D19981A82090519bC1626249984c908 contract ConditionalTokens is ERC1155 { using SafeMath for uint; ... CT Helper ContractString Utilities were added to the CT Helper Contract to support a method to return the position ID as a string **the scaffold eth debug contract getPositionId(…) returns the uint as floating point eth example: Ξ30538692964205559938227141519166067798763549412261626800343.848901573363871063//SPDX-License-Identifier: MIT pragma solidity >=0.8.0 <0.9.0; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; ... function getStringPositionId(IERC20 collateralToken, bytes32 collectionId) internal pure returns (string memory) { return Strings.toString(uint(keccak256(abi.encodePacked(collateralToken, collectionId)))); } Collateral Token ContractsThe Gist repository provides one contract to execute and mint multiple collateral tokens using different name and symbol. Two contracts are created and deployed in scaffold-eth as the deployed contract object uses the name of the contract as the key. **without doing this OOB the debug contract page will only show for one of the collateral tokens https://github.com/OwlWilderness/se-2/blob/gnostic-condition/packages/hardhat/contracts/GnosticTokens.sol//SPDX-License-Identifier: MIT pragma solidity >=0.8.0 <0.9.0; import { ConditionalTokens } from "./ConditionalTokens.sol"; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract GnosticToken0 is ERC20 { constructor(string memory name, string memory symbol) ERC20(name, symbol) {} function mint(address account, uint256 amount) external { _mint(account, amount); } } contract GnosticToken1 is ERC20 { constructor(string memory name, string memory symbol) ERC20(name, symbol) {} function mint(address account, uint256 amount) external { _mint(account, amount); } } Deploy Conditional and Collateral Token ContractsFork and Clone gnostic-condition repositoryFork / clone the gnostic-condition repository - reference the below article for instruction. https://mirror.xyz/quantumtekh.eth/jnuL3guybvgeXBFShILuiA53Pq9igs4jFcqYZpSqMNoDeploy Contracts On HardhatFollow instructions in Scaffold-eth 2 ReadMe to Yarn Install, Chain, Start and Deploy to start the hardhat chain local webhostFund Hardhat WalletOpen a new private window and navigate to http://localhost:3000/debug Click the Faucet Icon in the upper right to fund the hardhat wallet.Mint and Approve Collateral TokensCollateral Tokens are used to Mint Conditional Position Tokens. In this example we will mint two Collateral Tokens Gnostic Token 0 (GT0) and Gnostic Token 1 (GT1).Copy Wallet AddressClick the Address in the upper right to open the menu and Click Copy AddressNavigate to Gnostic Token 0Click the Debug Gnostic Contracts Tab then → the GnosticToken0 tab.Mint Gnostic Collateral Token 0Scroll to the Mint Token sectionPaste the copied wallet address into the address account field and enter 1000 into the uint256 amount field. Click SendNote Supply of GT0 increased to 1000Note the GnosticToken0 address by clicking the copy iconMint Gnostic Collateral Token 1Navigate to Gnostic Token 1Repeat Process to Mint Gnostic Token 1 - Scroll to Mint Area- Paste Copied Wallet Address into address account field- Enter 1000 into uint256 amount field- Copy / Note the GnosticToken1 addressSet Allowance for Conditional Token Contract to use CollateralNavigate to ConditionalTokens Debug Contract and Copy AddressNavigate to GnosticToken0 Approve SectionPaste copied address into the address spender field.Enter 1000 into the amount fieldClick SendRepeat Process for Gnostic Token 1Notesrecord addresses, values and hashes. these values will change after each deployment and are for illustration purposes only.AddressesHardhat Wallet Address : 0x0a3b031cC1234315a92E647889F9182BC061E8A0Conditional Token Address : 0x5FbDB2315678afecb367f032d93F642f64180aa3Gnostic Token 0 (GT0) : 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512Gnostic Token 1 (GT1) : 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0IDsParent Collection : 0x0000000000000000000000000000000000000000000000000000000000000000Question ID 1 : 0x0000000000000000000000000000000000000000000000000000000000000001Question ID 2 : 0x0000000000000000000000000000000000000000000000000000000000000002Conditional Token PreparationOracle : ETH ADDRESSQuestion ID : ANY 32 BYTES of HEXNumber of Possible Outcomes : BETWEEN 2-256 POSSIBLE OUTCOMESgetConditionId Question 1: 0xa9620c3b3514f4c96c9f53642913021e2ed08eb083748b5f615dc5f3c80b7000 Oracle : 0x0a3b031cC1234315a92E647889F9182BC061E8A0 Question ID 1 : 0x0000000000000000000000000000000000000000000000000000000000000001 # Outcomes: 3use same values and execute prepareConditiongetConditionId Question 2: 0x15d6a8d1501917bb78d09b863412bf66b9c9e2f5f1f624af75531406f454e7bb Oracle : 0x0a3b031cC1234315a92E647889F9182BC061E8A0 Question ID 2 : 0x0000000000000000000000000000000000000000000000000000000000000002 # Outcomes: 2use same values and execute prepareConditionCollection IDsCollection - Outcome B|C for Question 1 : 0x0f7deef25c034a8752aea625d5a7e2fe3fad44e9633026dd92688252a76be7f1 Parent ID: 0x0000000000000000000000000000000000000000000000000000000000000000 Condition ID Question 1 : 0xa9620c3b3514f4c96c9f53642913021e2ed08eb083748b5f615dc5f3c80b7000 Index Set: 6 = 0b110 = Outcome (B|C) Collection - Outcome A for Question 1: 0x1e4d7015a719ca11166cac05af32305e31a207fc15e6549aaee014f4e54d1c32 Parent ID: 0x0000000000000000000000000000000000000000000000000000000000000000 Condition ID Question 1 : 0xa9620c3b3514f4c96c9f53642913021e2ed08eb083748b5f615dc5f3c80b7000 Index Set: 1 = 0b001 = Outcome A Collection - Outcome Low for Question 2: 0x4f3e685bd90b864855a543862c9a5ccfdd004e0ed41966810e3421ef0352733d Parent ID: 0x0000000000000000000000000000000000000000000000000000000000000000 Condition ID Question 1 : 0x15d6a8d1501917bb78d09b863412bf66b9c9e2f5f1f624af75531406f454e7bb Index Set: 1 = 0b01 = Outcome Low Collection - Outcome Hi for Question 2: 0x4872a0885cbc2f9edb8ced8e5edb54349ee133a96ac996e94a003b0cde443ff6 Parent ID: 0x0000000000000000000000000000000000000000000000000000000000000000 Condition ID Question 1 : 0x15d6a8d1501917bb78d09b863412bf66b9c9e2f5f1f624af75531406f454e7bb Index Set: 2 = 0b10 = Outcome HiPosition IDsCollections:Collection - Outcome B|C for Question 1 : 0x0f7deef25c034a8752aea625d5a7e2fe3fad44e9633026dd92688252a76be7f1Collection - Outcome A for Question 1: 0x1e4d7015a719ca11166cac05af32305e31a207fc15e6549aaee014f4e54d1c32Collection - Outcome Low for Question 2: 0x4f3e685bd90b864855a543862c9a5ccfdd004e0ed41966810e3421ef0352733dCollection - Outcome Hi for Question 2: 0x4872a0885cbc2f9edb8ced8e5edb54349ee133a96ac996e94a003b0cde443ff6TokensGnostic Token 0 (GT0) : 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512Gnostic Token 1 (GT1) : 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0Position GT0-1 B|C : 69756881759866133805660629677137340800784931395161768631268343007553287298947 Position GT0-1 A : 82731255938747274424991476311812858093949303227342239819305777831695159296885 Position GT1-1 B|C : 39907225118877227855298033650136733790066605943132640619358681018232170696662 Position GT1-1 A : 71119352066877664618372522921430707264363198477866865446318236169980389097443 Position GT0-2 Low : 33407020960471868732595667962325811837077945823734802324599614554532694637363 Position GT0-2 Hi : 111110653929981865175832810059537209326101375996587576828500820462032281170479 Position GT1-2 Low : 22624642637007454965289107974225720027671607220739183332440370573482761255543 Position GT1-2 Hi: 26320361178311307871541764768252101128993509163924835565533731277595907344887Creating Positions with Conditional TokensSplit Positions with CollateralCreate Positions with the Collateral TokensGT0 Question 1 Positionaddress collateral token : Gnostic Token 0 (GT0) : 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512bytes32 parentCollectionId : 0x0000000000000000000000000000000000000000000000000000000000000000bytes32 conditionId : ConditionId Question 1: 0xa9620c3b3514f4c96c9f53642913021e2ed08eb083748b5f615dc5f3c80b7000uint256 partitions : [1,6] = [0b001 = Outcome A, 0b110 = Outcome 6]uint256 amount : 100GT1 Question 1 Positionaddress collateral token : Gnostic Token 0 (GT1) : 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0bytes32 parentCollectionId : 0x0000000000000000000000000000000000000000000000000000000000000000bytes32 conditionId : ConditionId Question 1: 0xa9620c3b3514f4c96c9f53642913021e2ed08eb083748b5f615dc5f3c80b7000uint256 partitions : [1,6] = [0b001 = Outcome A, 0b110 = Outcome 6]uint256 amount : 100GT0 Question 2 Positionaddress collateral token : Gnostic Token 0 (GT0) : 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512bytes32 parentCollectionId : 0x0000000000000000000000000000000000000000000000000000000000000000bytes32 conditionId : ConditionId Question 1: 0x15d6a8d1501917bb78d09b863412bf66b9c9e2f5f1f624af75531406f454e7bbuint256 partitions : [1,2] = [0b01 = Low, 0b10 = Hi]uint256 amount : 100GT1 Question 2 Positionaddress collateral token : Gnostic Token 0 (GT1) : 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0bytes32 parentCollectionId : 0x0000000000000000000000000000000000000000000000000000000000000000bytes32 conditionId : ConditionId Question 1: 0x15d6a8d1501917bb78d09b863412bf66b9c9e2f5f1f624af75531406f454e7bbuint256 partitions : [1,2] = [0b01 = Low, 0b10 = Hi]uint256 amount : 100Use Balance Of and Position ID to read back positions:Enter Wallet Address in address account fieldEnter Position ID in uint256 id field ## Publication Information - [tekh](https://paragraph.com/@quantumtekh/): Publication homepage - [All Posts](https://paragraph.com/@quantumtekh/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@quantumtekh): Subscribe to updates