### Install Tableland SDK Source: https://docs.tableland.xyz/sdk/walkthroughs/orm Install the @tableland/sdk package to get started with Tableland. ```bash npm install @tableland/sdk ``` -------------------------------- ### SQL Parser Setup Source: https://docs.tableland.xyz/sdk/walkthroughs/sql-parser Guide on how to set up the SQL parser by importing and initializing the `init` function. ```APIDOC ## Setup In your source file, import the `init` function from the SQL parser, and then call the function to initialize the parser. This add the `sqlparser` object to the global namespace, `globalThis`. ```javascript import { init } from "@tableland/sqlparser"; await init(); ``` Because the global namespace is used, you can call the `sqlparser` object from anywhere in your code, which should always be preceded with `await` since it's an asynchronous function. If you run into issues during this first step, it might be an issue with loading WASM, which powers the parser. In this instance, you can import `__wasm` and use it to conditionally check if WASM is loaded, then calling `init`: ```javascript import { init, __wasm } from "@tableland/sqlparser"; if (__wasm == null) { await init(); } ``` ``` -------------------------------- ### Initialize Tableland CLI Source: https://docs.tableland.xyz/cli/init Run this command to start the interactive setup process for creating a configuration file. ```bash tableland init ``` -------------------------------- ### Hardhat Deployment Script - Initial Setup Source: https://docs.tableland.xyz/smart-contracts/parsing-registry-events This script deploys an example contract and retrieves its deployment transaction. Ensure the `starter` variable is correctly assigned to your contract instance. ```javascript import { ethers } from "hardhat"; import { ITablelandTables__factory as TablelandTables } from "@tableland/evm"; async function main() { // Deploy the Example contract const Example = await ethers.getContractFactory("Example"); const example = await Example.deploy(); await example.waitForDeployment(); console.log( `Example contract deployed to '${await example.getAddress()}'.\n` ); // Make sure the transaction exists const deployTx = starter.deploymentTransaction(); if (!deployTx) { throw new Error("Deployment transaction not found"); } } main().catch((error) => { console.error(error); process.exitCode = 1; }); ``` -------------------------------- ### Setup local Tableland network for tests Source: https://docs.tableland.xyz/local-tableland/testing Configure and start a local Tableland network instance for testing. Ensure the `LocalTableland` instance is started before tests and shut down afterwards. A timeout is recommended for `before` hooks to allow network initialization. ```javascript import { after, before } from "mocha"; import { LocalTableland } from "@tableland/local"; const lt = new LocalTableland({ silent: false }); before(async function () { this.timeout(30000); lt.start(); await lt.isReady(); }); after(async function () { await lt.shutdown(); }); ``` -------------------------------- ### Package Manager Command Examples Source: https://docs.tableland.xyz/contribute/style-guide Manual examples of equivalent commands for npm, yarn, and pnpm. ```bash npm run build npm install npm run start ``` ```bash yarn build yarn add yarn run start ``` ```bash pnpm run build pnpm add pnpm run start ``` -------------------------------- ### Install Tableland SDK (Yarn) Source: https://docs.tableland.xyz/playbooks/frameworks/nextjs Install the Tableland SDK using Yarn. ```bash yarn add @tableland/sdk ``` -------------------------------- ### Install Tableland SDK (pnpm) Source: https://docs.tableland.xyz/playbooks/frameworks/nextjs Install the Tableland SDK using pnpm. ```bash pnpm add @tableland/sdk ``` -------------------------------- ### Install web3.py with poetry Source: https://docs.tableland.xyz/playbooks/frameworks/python Install the web3.py library using poetry. ```bash poetry add web3 ``` -------------------------------- ### Install Tableland SDK and JETI Source: https://docs.tableland.xyz/playbooks/integrations/ipfs Install the necessary packages using your preferred package manager. ```bash npm install @tableland/sdk @tableland/jeti ``` ```bash yarn add @tableland/sdk @tableland/jeti ``` ```bash pnpm add @tableland/sdk @tableland/jeti ``` -------------------------------- ### Query Example and Response Source: https://docs.tableland.xyz/validator/api/query Example requests and the corresponding JSON response format. ```bash curl -X GET https://testnets.tableland.network/api/v1/query?statement=select%20%2A%20from%20healthbot_80002_1 \ -H 'Accept: application/json' ``` ```bash curl -L 'https://testnets.tableland.network/api/v1/query' \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -d '{ "statement": "select * from healthbot_80002_1" }' ``` ```json [ { "counter": 148247 } ] ``` -------------------------------- ### Install web3.py with pip Source: https://docs.tableland.xyz/playbooks/frameworks/python Install the web3.py library using pip. ```bash pip install web3 ``` -------------------------------- ### Install Tableland SDK (npm) Source: https://docs.tableland.xyz/playbooks/frameworks/nextjs Install the Tableland SDK using npm. ```bash npm install --save @tableland/sdk ``` -------------------------------- ### Install Tableland SDK and Lit SDK with Yarn Source: https://docs.tableland.xyz/playbooks/integrations/lit Install the Tableland SDK, Lit SDK (v3.x), and the `siwe` package using Yarn. This setup is necessary for implementing private data solutions with Tableland and Lit Protocol. ```bash yarn add @tableland/sdk @lit-protocol/lit-node-client siwe ``` -------------------------------- ### Start nodes and deploy contracts Source: https://docs.tableland.xyz/smart-contracts/hardhat-plugin Commands to start the local nodes and deploy contracts to the network. ```bash npx hardhat node --network local-tableland ``` ```bash npx hardhat run scripts/deploy.js --network localhost ``` ```bash npx hardhat run scripts/deploy.js --network local-tableland ``` -------------------------------- ### Install Tableland Solidity Library Source: https://docs.tableland.xyz/quickstarts Install the Tableland EVM library and OpenZeppelin contracts for smart contract development. ```bash npm install @tableland/evm @openzeppelin/contracts ``` -------------------------------- ### Install Tableland Python SDK Source: https://docs.tableland.xyz/playbooks/frameworks/python Installation commands for the experimental tableland library. ```bash pip install tableland ``` ```bash poetry add tableland ``` ```bash pipenv install tableland ``` -------------------------------- ### Install Tableland CLI with npm Source: https://docs.tableland.xyz/cli Install the CLI tool globally using npm. Ensure you have Node.js and npm installed. ```bash npm install -g @tableland/cli@latest ``` -------------------------------- ### Install Tableland CLI with pnpm Source: https://docs.tableland.xyz/cli Install the CLI tool globally using pnpm. Ensure you have Node.js and pnpm installed. ```bash pnpm add -g @tableland/cli@latest ``` -------------------------------- ### Install Tableland SDK and Node Helpers Source: https://docs.tableland.xyz/sdk/database/aliases Commands to install the necessary packages for Tableland development. ```bash npm install --save @tableland/sdk @tableland/node-helpers ``` ```bash yarn add @tableland/sdk @tableland/node-helpers ``` ```bash pnpm add @tableland/sdk @tableland/node-helpers ``` -------------------------------- ### Install web3.py with pipenv Source: https://docs.tableland.xyz/playbooks/frameworks/python Install the web3.py library using pipenv. ```bash pipenv install web3 ``` -------------------------------- ### Install Tableland SDK for Node.js Source: https://docs.tableland.xyz/quickstarts Install the SDK and ethers for signer management in a Node.js environment. ```bash npm install @tableland/sdk ethers ``` -------------------------------- ### Install JETI and SDK dependencies Source: https://docs.tableland.xyz/sdk/plugins Install the required packages using your preferred package manager. ```bash npm install @tableland/jeti @tableland/sdk ``` ```bash yarn add @tableland/jeti @tableland/sdk ``` ```bash pnpm add @tableland/jeti @tableland/sdk ``` -------------------------------- ### Install OpenZeppelin and Tableland dependencies Source: https://docs.tableland.xyz/tutorials/dynamic-nft-solidity Install the necessary upgradeable contracts and Tableland EVM packages for the project. ```bash npm install @openzeppelin/contracts-upgradeable @tableland/evm ``` -------------------------------- ### Install SQL Parser Source: https://docs.tableland.xyz/sdk/walkthroughs/sql-parser Install the package using your preferred package manager. ```bash npm install @tableland/sqlparser ``` ```bash yarn add @tableland/sqlparser ``` ```bash pnpm add @tableland/sqlparser ``` -------------------------------- ### Install Tableland Studio CLI Source: https://docs.tableland.xyz/studio/cli Install the CLI tool globally using your preferred package manager. ```bash npm install -g @tableland/studio-cli ``` ```bash yarn global add @tableland/studio-cli ``` ```bash pnpm add -g @tableland/studio-cli ``` -------------------------------- ### Install Tableland Local via Yarn Source: https://docs.tableland.xyz/local-tableland/cli Install the Tableland local network tool globally using Yarn. ```bash yarn global add @tableland/local@latest ``` -------------------------------- ### Install Tableland Local via pnpm Source: https://docs.tableland.xyz/local-tableland/cli Install the Tableland local network tool globally using pnpm. ```bash pnpm add -g @tableland/local@latest ``` -------------------------------- ### Get Table Schema Information Source: https://docs.tableland.xyz/cli Use this command to retrieve detailed schema information for a specific table. No setup is required beyond having the CLI installed. ```shell tableland schema ``` -------------------------------- ### Example: SUBSTR with length Source: https://docs.tableland.xyz/sql/functions Extracts a substring of a specified length starting from a given position. ```sql SELECT substr(val,7,3) FROM my_table; ``` -------------------------------- ### Install Tableland SDK Source: https://docs.tableland.xyz/playbooks/frameworks/hardhat Install the `@tableland/sdk` package as a development dependency using npm, Yarn, or pnpm. ```bash npm install --save-dev @tableland/sdk ``` ```bash yarn add --dev @tableland/sdk ``` ```bash pnpm add --save-dev @tableland/sdk ``` -------------------------------- ### Query via cURL Source: https://docs.tableland.xyz/api/validator/query-the-network Example of a GET request to the query endpoint using cURL. ```bash curl -L 'https://testnets.tableland.network/api/v1/query' \ -H 'Accept: application/json' ``` -------------------------------- ### Install Tableland Local via npm Source: https://docs.tableland.xyz/local-tableland/cli Install the Tableland local network tool globally using npm. ```bash npm install -g @tableland/local@latest ``` -------------------------------- ### Example: SUBSTR from a specific position Source: https://docs.tableland.xyz/sql/functions Extracts a substring starting from a specified position to the end of the string. ```sql SELECT substr(val,7) FROM my_table; ``` -------------------------------- ### Local Tableland Startup Logs Source: https://docs.tableland.xyz/local-tableland Example output showing the initialization of the Registry (hardhat) and Validator components. ```text [Registry] Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/ [Registry] [Registry] [Registry] Accounts [Registry] ======== --- [Registry] eth_sendTransaction [Registry] Contract deployment: TablelandTables [Registry] Contract address: 0x5fbdb2315678afecb367f032d93f642f64180aa3 --- [Validator] 8:26PM INF state hash block_number=6 chain_id=31337 component=eventprocessor elapsed_time=5 goversion=go1.19.1 hash=edde6a99dd8d30efb48f8a60de13f53b84a6c6f1 severity=Info version=7144099 [Validator] [Validator] 8:26PM DBG executing create-table event chain_id=31337 component=txnscope goversion=go1.19.1 owner=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 severity=Debug statement="create table healthbot_31337 (counter integer);" token_id=1 txn_hash=0x8459cc42f646c40233966c3ff366f16a4b6678045f23536c3a1839e459a8cd05 version=7144099 ``` -------------------------------- ### Example: INSTR to find substring position Source: https://docs.tableland.xyz/sql/functions Finds the starting position of a substring within a string. ```sql SELECT instr('Hello','o') from my_table; ``` -------------------------------- ### Example Configuration File Source: https://docs.tableland.xyz/cli/init The resulting .tablelandrc.json file structure after completing the initialization prompts. ```json { "privateKey": "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d", "chain": "local-tableland", "providerUrl": "http://127.0.0.1:8545", "aliases": "./tableland.aliases.json" } ``` -------------------------------- ### Get table name Source: https://docs.tableland.xyz/smart-contracts/sql-helpers Example of retrieving a formatted table name using the SQLHelpers library. ```solidity uint256 private _tableId; // Unique table ID—set once table created string private constant _TABLE_PREFIX = "my_table"; // Custom table prefix function getTableName() external view returns (string memory) { return SQLHelpers.toNameFromId(_TABLE_PREFIX, _tableId); } ``` -------------------------------- ### Install web3.storage Client (npm) Source: https://docs.tableland.xyz/playbooks/integrations/ipfs Installs the web3.storage client library using npm. This is required for persisting data on the Filecoin network. ```bash npm install @web3-storage/w3up-client ``` -------------------------------- ### Deploy and Configure Example Contract Source: https://docs.tableland.xyz/smart-contracts/row-level-access This contract demonstrates how to create and manage a Tableland table. It includes functions for creating a table, inserting data, updating data, and setting access control policies. ```solidity // SPDX-License-Identifier: MIT pragma solidity >=0.8.10 <0.9.0; import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import {TablelandDeployments} from "@tableland/evm/contracts/utils/TablelandDeployments.sol"; import {SQLHelpers} from "@tableland/evm/contracts/utils/SQLHelpers.sol"; contract Example is Ownable { // Store relevant table info uint256 private _tableId; // Unique table ID string private constant _TABLE_PREFIX = "access_control"; // Custom table prefix // Constructor that creates a simple table with a an `id` and `val` column constructor() { // Create a table _tableId = TablelandDeployments.get().create( address(this), SQLHelpers.toCreateFromSchema( "id integer primary key," "address text," "val text", _TABLE_PREFIX ) ); } // Let anyone insert into the table function insertIntoTable(string memory val) external { TablelandDeployments.get().mutate( address(this), // Table owner, i.e., this contract _tableId, SQLHelpers.toInsert( _TABLE_PREFIX, _tableId, "address,val", string.concat( SQLHelpers.quote(Strings.toHexString(msg.sender)), // Insert the caller's address ",", SQLHelpers.quote(val) // Wrap strings in single quotes with the `quote` method ) ) ); } // Update only the row that the caller inserted function updateTable(string memory val) external { // Set the values to update string memory setters = string.concat("val=", SQLHelpers.quote(val)); // Specify filters for which row to update string memory filters = string.concat( "address=", SQLHelpers.quote(Strings.toHexString(msg.sender)) ); // Mutate a row at `address` with a new `val`—gating for the correct row is handled by the controller contract TablelandDeployments.get().mutate( address(this), _tableId, SQLHelpers.toUpdate(_TABLE_PREFIX, _tableId, setters, filters) ); } // Set the ACL controller to enable row-level writes with dynamic policies function setAccessControl(address controller) external onlyOwner { TablelandDeployments.get().setController( address(this), // Table owner, i.e., this contract _tableId, controller // Set the controller address—a separate controller contract ); } // Return the table ID function getTableId() external view returns (uint256) { return _tableId; } // Return the table name function getTableName() external view returns (string memory) { return SQLHelpers.toNameFromId(_TABLE_PREFIX, _tableId); } ``` -------------------------------- ### Initialize Tableland Database Connection Source: https://docs.tableland.xyz/playbooks/frameworks/python Sets up the Database instance with a private key and provider URI. ```python from tableland import Database private_key = "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" # Replace with your private key db = Database( private_key=private_key, provider_uri="http://localhost:8545", # Replace with your chain RPC provider URL ) ``` -------------------------------- ### Local Tableland Setup Fixtures Source: https://docs.tableland.xyz/sdk/walkthroughs/testing Set up global fixtures for Mocha to start and stop the local Tableland network before and after tests. Ensure `silent` or `verbose` is configured as needed. ```javascript import { after, before } from "mocha"; import { LocalTableland } from "@tableland/local"; // Set `silent` or `verbose` with boolean values // You'll likely want to silence logging during tests const lt = new LocalTableland({ silent: true }); before(async function () { this.timeout(15000); lt.start(); await lt.isReady(); }); after(async function () { await lt.shutdown(); }); ``` -------------------------------- ### Wagmi v2 Configuration with RainbowKit Source: https://docs.tableland.xyz/playbooks/frameworks/wagmi Configure Wagmi v2 using `getDefaultConfig` for a streamlined setup with RainbowKit. This example includes mainnet and testnet chains, and uses `http` transport. ```javascript import "@rainbow-me/rainbowkit/styles.css"; import { getDefaultConfig } from "@rainbow-me/rainbowkit"; import * as chain from "wagmi/chains"; import { http } from "viem"; const chains = [ chain.mainnet, chain.polygon, chain.optimism, chain.arbitrum, chain.arbitrumNova, chain.filecoin, ...(import.meta.ENABLE_TESTNETS === "true" ? [ chain.arbitrumSepolia, chain.sepolia, chain.polygonAmoy, chain.optimismSepolia, chain.baseSepolia, chain.filecoinCalibration, chain.hardhat, ] : []), ]; const transports = Object.fromEntries(chains.map((c) => [c.id, http()])); export const config = getDefaultConfig({ appName: "Tableland Starter", chains, transports, projectId: import.meta.env.VITE_WALLET_CONNECT_PROJECT_ID ?? "", }); ``` -------------------------------- ### Retrieve Transaction Receipt Source: https://docs.tableland.xyz/cli/receipt Use this command to get mutating query transaction information. Include the `--chain` flag if a config file has not been created. This example retrieves block number, table ID, and chain ID. ```bash tableland receipt 0x808afd525b8bac7d7d74ba9e0b214984e6862cf83e3b42cb181f8f415be57c9e --chain polygon-amoy ``` -------------------------------- ### Install web3.storage Client (pnpm) Source: https://docs.tableland.xyz/playbooks/integrations/ipfs Installs the web3.storage client library using pnpm. This is required for persisting data on the Filecoin network. ```bash pnpm add @web3-storage/w3up-client ``` -------------------------------- ### Validator API Overview Source: https://docs.tableland.xyz/sdk/validator The Validator API allows for direct access to a Tableland Validator node. Setting up a validator node connection starts by importing a `Validator`. The methods defined in the Gateway REST API are exposed in the SDK, such as checking the `health` of a node or getting a table's name. ```APIDOC ## Validator API The Validator API allows for direct access to a Tableland Validator node. Setting up a validator node connection starts by importing a `Validator`. The methods defined in the Gateway REST API are exposed in the SDK, such as checking the `health` of a node or getting a table's name. Note that a validator can use a `Database` instance's `config`, which requires a `baseUrl` param in order to connect to and query a validator node. Alternatively, the SDK's `helpers` module provides a `getBaseUrl` function that can be used to determine the correct URL for a given chain ID. ``` -------------------------------- ### Install remixd with Yarn Source: https://docs.tableland.xyz/smart-contracts/using-remix Install the remixd package globally using Yarn. This is an alternative to npm for installing the necessary package. ```bash yarn global add @remix-project/remixd ``` -------------------------------- ### Initialize Tableland and Lit Client Source: https://docs.tableland.xyz/playbooks/integrations/lit Sets up the provider, signer, database connection, and Lit client, then creates a new table. ```javascript // Set up a signer (note: replace with your own private key & API key) const privateKey = "your_private_key"; const provider = getDefaultProvider( "https://eth-sepolia.g.alchemy.com/v2/" ); const wallet = new Wallet(privateKey); const signer = wallet.connect(provider); // Set up database and Lit client const db = new Database({ signer }); const client = new LitNodeClient({ debug: false }); await client.connect(); // Create a table, and note that our access control will use the `tableId` as a condition const tablePrefix = "lit_encrypt"; const createStmt = `CREATE TABLE ${tablePrefix} (id integer primary key, msg text, hash text)`; const { meta: create } = await db.prepare(createStmt).run(); const tableName = create.txn?.names[0] ?? ""; const tableId = create.txn?.tableIds[0] ?? ""; await create.txn?.wait(); ``` -------------------------------- ### Example Deployment Output Source: https://docs.tableland.xyz/playbooks/frameworks/hardhat Sample output from a successful contract deployment and Tableland data query. ```text Lock deployed to 0x98dd705fBD9B12B90b8C997afd0362EB7a9fbe37 Data in table 'my_table_31337_2': [ { "id": 0, "name": "Bobby Tables" } ] ``` -------------------------------- ### Install Tableland CLI with Yarn Source: https://docs.tableland.xyz/cli Install the CLI tool globally using Yarn. Ensure you have Node.js and Yarn installed. ```bash yarn global add @tableland/cli@latest ``` -------------------------------- ### Install remixd with pnpm Source: https://docs.tableland.xyz/smart-contracts/using-remix Install the remixd package globally using pnpm. This is another alternative package manager for installing remixd. ```bash pnpm add -g @remix-project/remixd ``` -------------------------------- ### Create Studio Deployment Source: https://docs.tableland.xyz/studio/cli/deployment Deploy a table blueprint to a specified network. Ensure you provide the table blueprint name, project ID, chain name, provider RPC URL, and the private key of the account that will be writing data. ```bash studio deployment create test_table --pid eac4b0f2-ab4d-41ec-9789-19f0a4905615 --chain local-tableland --providerUrl http://127.0.0.1:8545 --privateKey 59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d ``` ```json { "tableId": "3ecb77e3-246e-4671-8695-8823dbb7c23d", "environmentId": "03b21226-3ed1-44c6-8100-901b6288c565", "tableName": "my_table_80002_7726", "chainId": 80002, "tokenId": "2", "blockNumber": 41179459, "txnHash": "0x209195da1f735e6872ff8034d14b0fc3151a68533427a388e4adda9fa10d5ce1", "createdAt": "2023-10-14T01:38:57.585Z" } ``` -------------------------------- ### Install Tableland EVM Package (pnpm) Source: https://docs.tableland.xyz/quickstarts/smart-contract-quickstart Install the Tableland EVM package using pnpm. This is another alternative package manager for installing the Tableland contracts. ```bash pnpm add @tableland/evm ``` -------------------------------- ### Install JETI and Tableland SDK Source: https://docs.tableland.xyz/sdk/plugins/pinning-to-ipfs Install the necessary packages for JETI and the Tableland SDK using npm, Yarn, or pnpm. ```bash npm install @tableland/jeti @tableland/sdk ``` ```bash yarn add @tableland/jeti @tableland/sdk ``` ```bash pnpm add @tableland/jeti @tableland/sdk ``` -------------------------------- ### Install Tableland EVM Package (Yarn) Source: https://docs.tableland.xyz/quickstarts/smart-contract-quickstart Install the Tableland EVM package using Yarn. This is an alternative package manager for installing the necessary Tableland contracts. ```bash yarn add @tableland/evm ``` -------------------------------- ### Install drizzle-orm Source: https://docs.tableland.xyz/sdk/walkthroughs/orm Install the drizzle-orm dependency to integrate it with your project. ```bash npm install drizzle-orm ``` -------------------------------- ### Install web3.storage Client (Yarn) Source: https://docs.tableland.xyz/playbooks/integrations/ipfs Installs the web3.storage client library using Yarn. This is required for persisting data on the Filecoin network. ```bash yarn add @web3-storage/w3up-client ``` -------------------------------- ### Install d1-orm Source: https://docs.tableland.xyz/sdk/walkthroughs/orm Install the d1-orm dependency to use it with Tableland. ```bash npm install d1-orm ``` -------------------------------- ### Install @tableland/local Source: https://docs.tableland.xyz/sdk/walkthroughs/testing Install the `@tableland/local` package as a development dependency. ```bash npm i -D @tableland/local ``` -------------------------------- ### Connect to Local Tableland with web3.py Source: https://docs.tableland.xyz/playbooks/frameworks/python Set up a web3 instance and signer using a provider URI and private key for connecting to a local Tableland instance. ```python # Define provider and private key provider_uri = "http://localhost:8545" private_key = "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" # Set up web3 instance and signer w3 = Web3(Web3.HTTPProvider(provider_uri)) signer = Account.from_key(private_key) ``` -------------------------------- ### Initialize Studio CLI Configuration Source: https://docs.tableland.xyz/quickstarts/studio-quickstart Initialize the Studio CLI configuration by running the 'init' command. This command prompts for your default chain, private key, and provider URL, creating a 'tablelandrc.json' file to store these settings locally. ```bash studio init ``` -------------------------------- ### Install wagmi v1, RainbowKit v1, and Tableland SDK (pnpm) Source: https://docs.tableland.xyz/playbooks/frameworks/wagmi Install wagmi v1, RainbowKit v1, Tableland SDK, and ethers using pnpm. ```bash pnpm add wagmi@^1 @rainbow-me/rainbowkit@^1 @tableland/sdk ethers ``` -------------------------------- ### Initialize Hardhat Project Source: https://docs.tableland.xyz/playbooks/frameworks/hardhat Command to scaffold a new Hardhat project. ```bash npx hardhat ``` -------------------------------- ### Install wagmi v1, RainbowKit v1, and Tableland SDK (npm) Source: https://docs.tableland.xyz/playbooks/frameworks/wagmi Install wagmi v1, RainbowKit v1, Tableland SDK, and ethers using npm. ```bash npm install wagmi@^1 @rainbow-me/rainbowkit@^1 @tableland/sdk ethers ``` -------------------------------- ### Implement Tableland Operations in Solidity Source: https://docs.tableland.xyz/quickstarts/smart-contract-quickstart A full smart contract example demonstrating table creation, insertion, updates, deletion, and access control configuration using Tableland's SQLHelpers. ```solidity // SPDX-License-Identifier: MIT pragma solidity >=0.8.10 <0.9.0; import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol"; import {TablelandDeployments} from "@tableland/evm/contracts/utils/TablelandDeployments.sol"; import {SQLHelpers} from "@tableland/evm/contracts/utils/SQLHelpers.sol"; contract Example is ERC721Holder { // Store relevant table info uint256 private _tableId; // Unique table ID string private constant _TABLE_PREFIX = "my_table"; // Custom table prefix // Creates a simple table with an `id` and `val` column function createTable() public payable { _tableId = TablelandDeployments.get().create( address(this), SQLHelpers.toCreateFromSchema( "id integer primary key," // Notice the trailing comma "val text", _TABLE_PREFIX ) ); } // Let anyone insert into the table function insertIntoTable(uint256 id, string memory val) external { TablelandDeployments.get().mutate( address(this), // Table owner, i.e., this contract _tableId, SQLHelpers.toInsert( _TABLE_PREFIX, _tableId, "id,val", string.concat( Strings.toString(id), // Convert to a string ",", SQLHelpers.quote(val) // Wrap strings in single quotes with the `quote` method ) ) ); } // Update only the row that the caller inserted function updateTable(uint256 id, string memory val) external { // Set the values to update string memory setters = string.concat("val=", SQLHelpers.quote(val)); // Specify filters for which row to update string memory filters = string.concat( "id=", Strings.toString(id) ); // Mutate a row at `id` with a new `val` TablelandDeployments.get().mutate( address(this), _tableId, SQLHelpers.toUpdate(_TABLE_PREFIX, _tableId, setters, filters) ); } // Delete a row from the table by ID function deleteFromTable(uint256 id) external { // Specify filters for which row to delete string memory filters = string.concat( "id=", Strings.toString(id) ); // Mutate a row at `id` TablelandDeployments.get().mutate( address(this), _tableId, SQLHelpers.toDelete(_TABLE_PREFIX, _tableId, filters) ); } // Set the ACL controller to enable row-level writes with dynamic policies function setAccessControl(address controller) external { TablelandDeployments.get().setController( address(this), // Table owner, i.e., this contract _tableId, controller // Set the controller address—a separate controller contract ); } // Return the table ID function getTableId() external view returns (uint256) { return _tableId; } // Return the table name function getTableName() external view returns (string memory) { return SQLHelpers.toNameFromId(_TABLE_PREFIX, _tableId); } } ``` -------------------------------- ### Configure Signer and Provider Source: https://docs.tableland.xyz/sdk/plugins Set up the wallet and provider to connect to the local development network. ```javascript const privateKey = "59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"; const wallet = new Wallet(privateKey); // To avoid connecting to the browser wallet (locally, port 8545). // For example: "https://polygon-amoy.g.alchemy.com/v2/YOUR_ALCHEMY_KEY" const provider = getDefaultProvider("http://127.0.0.1:8545"); const signer = wallet.connect(provider); ``` -------------------------------- ### Install @tableland/evm with pnpm Source: https://docs.tableland.xyz/smart-contracts/tableland-deployments Install the @tableland/evm library as a development dependency using pnpm. ```bash pnpm add --save-dev @tableland/evm ``` -------------------------------- ### Basic App Component Setup (TypeScript) Source: https://docs.tableland.xyz/playbooks/frameworks/nextjs Set up the basic App component in Next.js with TypeScript, importing necessary modules and declaring window. ```typescript "use client"; import { Database } from "@tableland/sdk"; import { Signer, BrowserProvider } from "ethers"; import { useState } from "react"; declare const window: any; export default function Home() { return <>; } ``` -------------------------------- ### Install @tableland/evm with Yarn Source: https://docs.tableland.xyz/smart-contracts/tableland-deployments Install the @tableland/evm library as a development dependency using Yarn. ```bash yarn add --dev @tableland/evm ``` -------------------------------- ### Install wagmi v1, RainbowKit v1, and Tableland SDK (Yarn) Source: https://docs.tableland.xyz/playbooks/frameworks/wagmi Install wagmi v1, RainbowKit v1, Tableland SDK, and ethers using Yarn. ```bash yarn add wagmi@^1 @rainbow-me/rainbowkit@^1 @tableland/sdk ethers ``` -------------------------------- ### Install @tableland/evm with npm Source: https://docs.tableland.xyz/smart-contracts/tableland-deployments Install the @tableland/evm library as a development dependency using npm. ```bash npm install --save-dev @tableland/evm ``` -------------------------------- ### Create a New Project Source: https://docs.tableland.xyz/studio/cli/project Create a project with a name and description, optionally specifying a team ID. ```bash studio project create --teamId 3bb1d54b-bc06-4a29-8d61-39dc939e1406 new_test_proj "This is a test project." ``` ```json { "id": "de24e0a0-508c-4e1f-aa96-176a5ff2890a", "name": "new_test_proj", "description": "This is a test project.", "slug": "new_test_proj" } ``` -------------------------------- ### Install Ethers.js Source: https://docs.tableland.xyz/quickstarts/sdk-quickstart Install the latest version of ethers.js v6, which is required for Tableland operations. ```bash npm i --save ethers ``` -------------------------------- ### Install @tableland/local with pnpm Source: https://docs.tableland.xyz/local-tableland/testing Install the `@tableland/local` package as a development dependency using pnpm. ```bash pnpm add --save-dev @tableland/local@latest ``` -------------------------------- ### Install @tableland/local with Yarn Source: https://docs.tableland.xyz/local-tableland/testing Install the `@tableland/local` package as a development dependency using Yarn. ```bash yarn add --dev @tableland/local@latest ``` -------------------------------- ### Basic App Component Setup (JavaScript) Source: https://docs.tableland.xyz/playbooks/frameworks/nextjs Set up the basic App component in Next.js, importing necessary modules from Tableland SDK and React. ```javascript "use client"; import { Database } from "@tableland/sdk"; import { BrowserProvider } from "ethers"; import { useState } from "react"; export function Home() { return <>; } ```