iExec RLC 백서

iExec RLC

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 12쪽 중 8쪽

) to pay the iApp provider workerpoolMaxPrice : 2 , // Maximum amount (in nRLC) to pay the workerpool provider }); INFO All price parameters are in nRLC (nano RLC). The default value for all price parameters is 0, which means only free resources are accepted. Next Steps ​ Now that you know how to pay for iApp executions: Run iApp with ProtectedData Run iApp without ProtectedData ## /guides/use-iapp/run-iapp-with-ProtectedData Run iApp with a ProtectedData ​ When running an iApp, you can use multiple types of inputs. While ProtectedData is not mandatory to run an iApp, it's a powerful input type that allows you to process encrypted data from another provider. You can also use non-persistent inputs that come directly from you (the requester) and can change between each execution: Arguments, Input Files, and Secrets. These non-persistent inputs are perfect for customizing the iApp's behavior for each specific run. Prerequisites ​ First, install DataProtector in your project (for more details see DataProtector Getting Started ): npm yarn pnpm bun bash npm install @iexec/dataprotector bash yarn add @iexec/dataprotector bash pnpm add @iexec/dataprotector bash bun add @iexec/dataprotector Adding Protected Data ​ When working with protected data that contains multiple files, you can specify which file to process. ts // Process protected data with specific path const result = await dataProtectorCore . processProtectedData ({ protectedData : '0x123abc...' , app : '0x456def...' , path : 'data/input.csv' , }); The processProtectedData function will automatically download and decrypt the results for you. Nevertheless, if you want to retrieve results from a completed task, you can do so as follows: ts // Retrieve the result const taskResult = await dataProtectorCore . getResultFromCompletedTask ({ taskId : taskId , }); Adding Command-Line Arguments ​ Command-line arguments are passed as a string to the iApp and are visible on the blockchain. ts // Process protected data with arguments const result = await dataProtectorCore . processProtectedData ({ protectedData : '0x123abc...' , app : '0x456def...' , args : '--input-path data/input.csv --output-format json --verbose' , }); Adding Input Files ​ Input files are URLs to public files that the iApp can download during execution. ts // Process protected data with input files const result = await dataProtectorCore . processProtectedData ({ protectedData : '0x123abc...' , app : '0x456def...' , inputFiles : [ 'https://raw.githubusercontent.com/user/repo/main/config.json' , 'https://example.com/public-data.csv' , ], }); Adding Secrets ​ Secrets are sensitive data like API keys, passwords, or tokens that are stored securely and made available to the iApp as environment variables. ts // Process protected data with secrets const result = await dataProtectorCore . processProtectedData ({ protectedData : '0x123abc...' , app : '0x456def...' , secrets : { 1 : 'openai-api-key' , 2 : 'database-password' , }, }); ## /guides/use-iapp/run-iapp-without-ProtectedData Run iApp without a ProtectedData ​ When running an iApp, you can use multiple types of inputs even without ProtectedData. Non-persistent inputs come directly from you (the requester) and can change between each execution, making them perfect for customizing the iApp's behavior for each specific run. These inputs include Arguments, Input Files, and Secrets, which allow you to provide additional data, parameters, and configuration to enable processing and customize functionality. Prerequisites ​ First, install iExec SDK in your project (for more details see iExec SDK documentation ): npm yarn pnpm bun sh npm install iexec sh yarn add iexec sh pnpm add iexec sh bun add iexec Adding Command-Line Arguments ​ Command-line arguments are passed as a string to the iApp and are visible on the blockchain. ts // Basic arguments const requestorderToSign = await iexec . order . createRequestorder ({ app : '0x456def...' , category : 0 , appmaxprice : 10 , workerpool : '0xa5de76...' , params : 'arg1 arg2 arg3' , // Command-line arguments // Other parameters have default values }); const requestOrder = await iexec . order . signRequestorder ( requestorderToSign ); // Fetch app orders const appOrders = await iexec . orderbook . fetchAppOrderbook ({ app : '0x456def...' , // Filter by specific app }); if ( appOrders . orders . length === 0 ) { throw new Error ( 'No app orders found for the specified app' ); } // Fetch workerpool orders const workerpoolOrders = await iexec . orderbook . fetchWorkerpoolOrderbook ({ workerpool : '0xa5de76...' , // Filter by specific workerpool }); if ( workerpoolOrders . orders . length === 0 ) { throw new Error ( 'No workerpool orders found for the specified workerpool' ); } // Execute the task const taskId = await iexec . order . matchOrders ({ requestorder : requestOrder , apporder : appOrders . orders [ 0 ]. order , workerpoolorder : workerpoolOrders . orders [ 0 ]. order , }); Adding Input Files ​ Input files are URLs to public files that the iApp can download during execution. ts // Single input file const requestorderToSign = await iexec . order . createRequestorder ({ app : '0x456def...' , category : 0 , // Required: category for the request appmaxprice : 10 , workerpool : '0xa5de76...' , params : { iexec_input_files : [ 'https://example.com/config.json' , 'https://example.com/template.html' , 'https://example.com/data.csv' , ], }, }); const requestOrder = await iexec . order . signRequestorder ( requestorderToSign ); // Fetch app orders const appOrders = await iexec . orderbook . fetchAppOrderbook ({ app : '0x456def...' , // Filter by specific app }); if ( appOrders . orders . length === 0 ) { throw new Error ( 'No app orders found for the specified app' ); } // Fetch workerpool orders const workerpoolOrders = await iexec . orderbook . fetchWorkerpoolOrderbook ({ workerpool : '0xa5de76...' , // Filter by specific workerpool }); if ( workerpoolOrders . orders . length === 0 ) { throw new Error ( 'No workerpool orders found for the specified workerpool' ); } // Execute the task const taskId = await iexec . order . matchOrders ({ requestorder : requestOrder , apporder : appOrders . orders [ 0 ]. order , workerpoolorder : workerpoolOrders . orders [ 0 ]. order , }); Adding Secrets ​ Secrets are sensitive data like API keys, passwords, or tokens that are stored securely and made available to the iApp as environment variables. Browser ts // Basic secrets const requestorderToSign = await iexec . order . createRequestorder ({ app : '0x456def...' , category : 0 , // Required: category for the request appmaxprice : 10 , workerpool : '0xa5de76...' , params : { iexec_secrets : { 1 : 'api-key-12345' , 2 : 'database-password' , }, }, }); const requestOrder = await iexec . order . signRequestorder ( requestorderToSign ); // Fetch app orders const appOrders = await iexec . orderbook . fetchAppOrderbook ({ app : '0x456def...' , // Filter by specific app }); if ( appOrders . orders . length === 0 ) { throw new Error ( 'No app orders found for the specified app' ); } // Fetch workerpool orders const workerpoolOrders = await iexec . orderbook . fetchWorkerpoolOrderbook ({ workerpool : '0xa5de76...' , // Filter by specific workerpool }); if ( workerpoolOrders . orders . length === 0 ) { throw new Error ( 'No workerpool orders found for the specified workerpool' ); } // Execute the task const taskId = await iexec . order . matchOrders ({ requestorder : requestOrder , apporder : appOrders . orders [ 0 ]. order , workerpoolorder : workerpoolOrders . orders [ 0 ]. order , }); ## /guides/use-iapp/integrate-web3-messaging Integrate Web3 Messaging ​ This guide covers both Web3Mail (email) and Web3Telegram (Telegram) toolkit. The flow is the same, except that: For Web3Mail, you only need the user's email address. For Web3Telegram, you only need the user's Telegram Chat ID. Overview ​ (Telegram only) Get a Chat ID from the iExec bot Create the Protected Data using DataProtector Toolkit Grant access of your Protected Data Send the message using the relevant SDK (Web3Mail / Web3Telegram) You can send messages in two modes: single messages (one recipient at a time) or bulk campaigns (same message to multiple recipients efficiently). See step 4 below for details. 1. Retrieve the Telegram Chat ID (Telegram only) ​ Ask the recipient to open Telegram and start a conversation with @IExecWeb3TelegramBot . The bot replies with a unique Chat ID. TIP Once the Chat ID is protected, all messages will arrive within this bot conversation. The recipient can leave the conversation at any time to stop receiving messages. 2. Create the Protected Data ​ Protect the email address or Chat ID using DataProtector Core. Web3Mail Web3Telegram ts import { IExecDataProtectorCore , getWeb3Provider } from '@iexec/dataprotector' ; const web3Provider = getWeb3Provider ( 'PRIVATE_KEY' , 'RPC_URL' ); const dataProtectorCore = new IExecDataProtectorCore ( web3Provider ); const protectedData = await dataProtectorCore . protectData ({ data : { email : 'user@example.com' , }, }); ts import { IExecDataProtectorCore , getWeb3Provider } from '@iexec/dataprotector' ; const web3Provider = getWeb3Provider ( 'PRIVATE_KEY' , 'RPC_URL' ); const dataProtectorCore = new IExecDataProtectorCore ( web3Provider ); const protectedData = await dataProtectorCore . protectData ({ data : { telegram_chatId : '12345678' , }, }); 3. Grant Access ​ Grant permission for a sender and/or an app to contact the user. Choose the mode based on your use case: use Single Message mode for individual messages, or Bulk Campaigns mode for sending the same message to multiple recipients. Single Message Bulk Campaigns ts import { IExecDataProtectorCore , getWeb3Provider } from '@iexec/dataprotector' ; const web3Provider = getWeb3Provider ( 'PRIVATE_KEY' , 'RPC_URL' ); const dataProtectorCore = new IExecDataProtectorCore ( web3Provider ); const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , pricePerAccess : 3 , numberOfAccess : 10 , }); ts // allowBulk: true automatically sets pricePerAccess to 0 and numberOfAccess to unlimited const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : '0x123abc...' , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , allowBulk : true , }); 4. Send the Message ​ Single Messages ​ Send a message to a single recipient: Web3Mail - Single Web3Telegram - Single ts import { IExecWeb3mail , getWeb3Provider } from '@iexec/web3mail' ; const web3Provider = getWeb3Provider ( 'PRIVATE_KEY' , 'RPC_URL' ); const web3mail = new IExecWeb3mail ( web3Provider ); const sendEmail = await web3mail . sendEmail ({ protectedData : '0x123abc...' , emailSubject : 'My email subject' , emailContent : 'My email content' , }); ts import { IExecWeb3telegram , getWeb3Provider } from '@iexec/web3telegram' ; const web3Provider = getWeb3Provider ( 'PRIVATE_KEY' , 'RPC_URL' ); const web3telegram = new IExecWeb3telegram ( web3Provider ); const sendTelegram = await web3telegram . sendTelegram ({ protectedData : '0x123abc...' , senderName : 'Arthur' , telegramContent : 'My telegram message content' , }); Bulk Campaigns ​ Send the same message to multiple recipients efficiently. Bulk processing groups multiple protected data items (emails for Web3Mail or chat IDs for Web3Telegram) together, reducing gas fees and processing recipients in parallel across one or more transactions. To send a bulk campaign, follow these steps in order: Fetch contacts with bulk access capability using fetchMyContacts or fetchUserContacts with bulkOnly: true Prepare the campaign by calling prepareEmailCampaign (for Web3Mail) or prepareTelegramCampaign (for Web3Telegram). This creates a bulk request object that groups all recipients together Send the campaign by calling sendEmailCampaign (for Web3Mail) or sendTelegramCampaign (for Web3Telegram) with the prepared bulk request Prerequisites Before using bulk processing, ensure that recipients have granted access with allowBulk: true when calling grantAccess (see step 3 above). Web3Mail - Bulk Web3Telegram - Bulk ts import { IExecDataProtectorCore , getWeb3Provider } from '@iexec/dataprotector' ; import { IExecWeb3mail } from '@iexec/web3mail' ; const web3Provider = getWeb3Provider ( 'PRIVATE_KEY' , 'RPC_URL' ); const dataProtectorCore = new IExecDataProtectorCore ( web3Provider ); const web3mail = new IExecWeb3mail ( web3Provider ); // Steps 1-2: Executed by the recipient (protected data provider) // Step 1: Create Protected Data (see section 2) const protectedData = await dataProtectorCore . protectData ({ data : { email : 'user@example.com' , }, }); // Step 2: Grant access with bulk processing enabled (see section 3) const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : protectedData . address , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , allowBulk : true , }); // Steps 3-5: Executed by the sender (who wants to contact recipients) // Step 3: Fetch contacts with bulk access const contacts = await web3mail . fetchMyContacts ({ bulkOnly : true }); const grantedAccessArray = contacts . map (( contact ) => contact . grantedAccess ); // Step 4: Prepare the campaign const emailCampaign = await web3mail . prepareEmailCampaign ({ grantedAccesses : grantedAccessArray , emailSubject : 'Hello from My Awesome App!' , emailContent : 'Hello! This is a bulk email sent to all recipients.' , contentType : 'text/html' , }); // Step 5: Send the bulk campaign const { tasks } = await web3mail . sendEmailCampaign ({ campaignRequest : emailCampaign . campaignRequest , }); ts import { IExecDataProtectorCore , getWeb3Provider } from '@iexec/dataprotector' ; import { IExecWeb3telegram } from '@iexec/web3telegram' ; const web3Provider = getWeb3Provider ( 'PRIVATE_KEY' , 'RPC_URL' ); const dataProtectorCore = new IExecDataProtectorCore ( web3Provider ); const web3telegram = new IExecWeb3telegram ( web3Provider ); // Steps 1-2: Executed by the recipient (protected data provider) // Step 1: Create Protected Data (see section 2) const protectedData = await dataProtectorCore . protectData ({ data : { telegram_chatId : '12345678' , }, }); // Step 2: Grant access with bulk processing enabled (see section 3) const grantedAccess = await dataProtectorCore . grantAccess ({ protectedData : protectedData . address , authorizedApp : '0x456def...' , authorizedUser : '0x789cba...' , allowBulk : true , }); // Steps 3-5: Executed by the sender (who wants to contact recipients) // Step 3: Fetch contacts with bulk access const contacts = await web3telegram . fetchMyContacts ({ bulkOnly : true }); const grantedAccessArray = contacts . map (( contact ) => contact . grantedAccess ); // Step 4: Prepare the campaign const telegramCampaign = await web3telegram . prepareTelegramCampaign ({ grantedAccesses : grantedAccessArray , telegramContent : 'Hello! This is a bulk message sent to all recipients.' , senderName : 'My Awesome App' , }); // Step 5: Send the bulk campaign const { tasks } = await web3telegram . sendTelegramCampaign ({ campaignRequest : telegramCampaign . campaignRequest , }); Payment ​ Each message sent through Web3Mail or Web3Telegram requires payment in RLC tokens. For detailed information about payment methods and pricing, see the comprehensive guide: How to pay for executions ## /references/iapp-generator/getting-started Getting Started ​ Prerequisites ​ Before using the iApp Generator, make sure you have: 📦 Node.js v20+ (for javascript iApps) Download → 🐍 Python 3.8+ (for Python iApps) Download → 🐳 Docker installed Download → 🐳 DockerHub Account Sign Up → 💰 RLC Tokens Learn More → 🔍 Verify Docker Compatibility bash docker buildx inspect --bootstrap | grep -i platforms If linux/amd64 is not listed, update your Docker installation. Installation ​ npm yarn pnpm bun sh npm install -g @iexec/iapp sh yarn global add @iexec/iapp sh pnpm add -g @iexec/iapp sh bun add -g @iexec/iapp Once installed, generate the auto-completion script and add it to your shell by following the instructions: bash iapp completion ## /references/dataProtector/getting-started Getting Started ​ Overview ​ Prerequisites ​ Before getting started, ensure that you have the following installed on your system: - Node.js version 18 or higher - NPM (Node.js package manager) Installation ​ npm yarn pnpm bun sh npm install @iexec/dataprotector sh yarn add @iexec/dataprotector sh pnpm add @iexec/dataprotector sh bun add @iexec/dataprotector This package is an ESM package. Your project needs to use ESM too. Read more If you use it with Webpack , some polyfills will be needed. You can find a minimal working project here . Instantiate SDK ​ Browser NodeJS ts import { IExecDataProtectorCore } from '@iexec/dataprotector' ; const web3Provider = window . ethereum ; // Instantiate only the Core module const dataProtectorCore = new IExecDataProtectorCore ( web3Provider ); ts import { IExecDataProtectorCore , getWeb3Provider } from '@iexec/dataprotector' ; // Get Web3 provider from a private key const web3Provider = getWeb3Provider ( 'YOUR_PRIVATE_KEY' , 'RPC_URL' ); // Instantiate the Core module const dataProtectorCore = new IExecDataProtectorCore ( web3Provider ); Instantiate Without a Web3 Provider ​ For projects that only require read functions, you can instantiate the SDK without a Web3 provider. Singleton Modules Umbrella Module ts import { IExecDataProtectorCore } from '@iexec/dataprotector' ; // Instantiate only the Core module for read-only core methods const dataProtectorCore = new IExecDataProtectorCore ( 'RPC_URL' ); ts import { IExecDataProtector } from '@iexec/dataprotector' ; // Instantiate using the umbrella module for read-only functions const dataProtector = new IExecDataProtector ( 'RPC_URL' ); // Access to read-only core methods const dataProtectorCore = dataProtector . core ; Advanced Configuration ​ To add optional parameters, see advanced configuration . ## /references/dataProtector/methods/protectData protectData ​ The iExec tool suite supports deployment of applications where the user of the application has complete and total control over access to their data. This ensures privacy and security when invoking these applications. Through use of the protectData method, a user may encrypt and secure any type of data. Encryption occurs on the client side, supporting the user's control over their data. Usage ​ The method accepts a JSON object containing the data to encrypt and an optional name to identify the data. An email address, for example, may be submitted as: ts const protectedData = await dataProtectorCore . protectData ({ data : { email : 'example@gmail.com' , }, }); Your object may contain any number of custom keys. The following example illustrates protection of multiple categories of data within one object: ts const protectedData = await dataProtectorCore . protectData ({ data : { email : 'example@gmail.com' , SMTPserver : { port : 5000 , smtp_server : 'smtp.gmail.com' , }, }, }); INFO @iexec/dataprotector us
프로젝트로 돌아가기