|
| 1 | +--- |
| 2 | +title: Run iApp with ProtectedData |
| 3 | +description: |
| 4 | + Learn how to run iApp with encrypted protected data, arguments, and input files using the DataProtector toolkit for secure data processing |
| 5 | +--- |
| 6 | + |
| 7 | +# 📥 Run iApp with a ProtectedData |
| 8 | + |
| 9 | +When an iApp requires additional data or parameters to function, you can provide |
| 10 | +various types of inputs to customize its behavior and enable processing. This |
| 11 | +guide covers all the different ways to run an iApp with inputs using the |
| 12 | +DataProtector turnkey toolkit. |
| 13 | + |
| 14 | +## Possible Inputs |
| 15 | + |
| 16 | +iExec supports several types of inputs for iApp executions: |
| 17 | + |
| 18 | +1. **Protected Data**: Encrypted data processed within the TEE |
| 19 | +2. **Arguments**: Command-line arguments passed to the application |
| 20 | +3. **Input Files**: URLs to public files that the app can download |
| 21 | +4. **Secrets**: Sensitive data like API keys stored securely |
| 22 | + |
| 23 | +## Adding Protected Data |
| 24 | + |
| 25 | +When working with protected data that contains multiple files, you can specify |
| 26 | +which file to process. |
| 27 | + |
| 28 | +```ts twoslash |
| 29 | +import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector'; |
| 30 | + |
| 31 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 32 | +const dataProtectorCore = new IExecDataProtectorCore(web3Provider); |
| 33 | +// ---cut--- |
| 34 | +// Process protected data with specific path |
| 35 | +const result = await dataProtectorCore.processProtectedData({ |
| 36 | + protectedData: '0x123abc...', |
| 37 | + app: '0x456def...', |
| 38 | + path: 'data/input.csv', |
| 39 | +}); |
| 40 | +``` |
| 41 | + |
| 42 | +The `processProtectedData` function will automatically download and decrypt the |
| 43 | +results for you. Nevertheless, if you want to retrieve results from a completed |
| 44 | +task, you can do so as follows: |
| 45 | + |
| 46 | +```ts twoslash |
| 47 | +import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector'; |
| 48 | + |
| 49 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 50 | +const dataProtectorCore = new IExecDataProtectorCore(web3Provider); |
| 51 | +const taskId = '0x7ac398...'; |
| 52 | + |
| 53 | +// ---cut--- |
| 54 | +// Retrieve the result |
| 55 | +const taskResult = await dataProtectorCore.getResultFromCompletedTask({ |
| 56 | + taskId: taskId, |
| 57 | +}); |
| 58 | +``` |
| 59 | + |
| 60 | +## Adding Command-Line Arguments |
| 61 | + |
| 62 | +Command-line arguments are passed as a string to the iApp and are visible on the |
| 63 | +blockchain. |
| 64 | + |
| 65 | +```ts twoslash |
| 66 | +import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector'; |
| 67 | + |
| 68 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 69 | +const dataProtectorCore = new IExecDataProtectorCore(web3Provider); |
| 70 | +// ---cut--- |
| 71 | +// Process protected data with arguments |
| 72 | +const result = await dataProtectorCore.processProtectedData({ |
| 73 | + protectedData: '0x123abc...', |
| 74 | + app: '0x456def...', |
| 75 | + args: '--input-path data/input.csv --output-format json --verbose', |
| 76 | +}); |
| 77 | +``` |
| 78 | + |
| 79 | +## Adding Input Files |
| 80 | + |
| 81 | +Input files are URLs to public files that the iApp can download during |
| 82 | +execution. |
| 83 | + |
| 84 | +```ts twoslash |
| 85 | +import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector'; |
| 86 | + |
| 87 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 88 | +const dataProtectorCore = new IExecDataProtectorCore(web3Provider); |
| 89 | +// ---cut--- |
| 90 | +// Process protected data with input files |
| 91 | +const result = await dataProtectorCore.processProtectedData({ |
| 92 | + protectedData: '0x123abc...', |
| 93 | + app: '0x456def...', |
| 94 | + inputFiles: [ |
| 95 | + 'https://raw.githubusercontent.com/user/repo/main/config.json', |
| 96 | + 'https://example.com/public-data.csv', |
| 97 | + ], |
| 98 | +}); |
| 99 | +``` |
| 100 | + |
| 101 | +## Adding Secrets |
| 102 | + |
| 103 | +Secrets are sensitive data like API keys, passwords, or tokens that are stored |
| 104 | +securely and made available to the iApp as environment variables. |
| 105 | + |
| 106 | +```ts twoslash |
| 107 | +import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector'; |
| 108 | + |
| 109 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 110 | +const dataProtectorCore = new IExecDataProtectorCore(web3Provider); |
| 111 | +// ---cut--- |
| 112 | +// Process protected data with secrets |
| 113 | +const result = await dataProtectorCore.processProtectedData({ |
| 114 | + protectedData: '0x123abc...', |
| 115 | + app: '0x456def...', |
| 116 | + secrets: { |
| 117 | + 1: 'openai-api-key', |
| 118 | + 2: 'database-password', |
| 119 | + }, |
| 120 | +}); |
| 121 | +``` |
| 122 | + |
| 123 | +## Next Steps |
| 124 | + |
| 125 | +Now that you understand how to add inputs to iApp executions: |
| 126 | + |
| 127 | +- Check out our |
| 128 | + [How to Pay for Executions](/guides/use-iapp/how-to-pay-executions) guide |
0 commit comments