|
| 1 | +# How to pay for Web3mail |
| 2 | + |
| 3 | +[Web3Mail](../tools/web3mail) dev tool offers secure, blockchain-based |
| 4 | +communication by encrypting emails and protecting user privacy. |
| 5 | + |
| 6 | +The `sendEmail` function uses confidential computing power to encrypt and send |
| 7 | +messages, ensuring secure and decentralized email exchanges. |
| 8 | + |
| 9 | +This guide explains how to pay for Web3Mail's computing power using **vouchers** |
| 10 | +and **xRLC**, detailing the steps for each method. |
| 11 | + |
| 12 | +## Using Vouchers for Web3Mail |
| 13 | + |
| 14 | +### Step 1: Obtain a Voucher |
| 15 | + |
| 16 | +- **Acquire Vouchers**: Obtain vouchers through the |
| 17 | + [iExec Builder Dashboard](https://builder.iex.ec/). Note that the number of |
| 18 | + Web3Mail executions and the expiration time of each voucher is restricted |
| 19 | + based on its validity period. Refer to |
| 20 | + [pricing documentation](https://www.iex.ec/voucher) for more information. |
| 21 | +- **Support**: For specific limitations related to your voucher, please contact |
| 22 | + iExec Support. |
| 23 | + |
| 24 | +### Step 2: Use the Builder Dashboard |
| 25 | + |
| 26 | +<a href="https://builder.iex.ec/" target="_blank" rel="noreferrer" style="display: inline-block; margin-top: 20px"> |
| 27 | + <img src="/assets/builder-dashboard.png" alt="Builder dashboard screenshot"> |
| 28 | +</a> |
| 29 | + |
| 30 | +The iExec Builder Dashboard is a comprehensive tool for managing vouchers and |
| 31 | +resources, providing an intuitive interface for: |
| 32 | + |
| 33 | +- **Claiming Vouchers**: Builders can claim vouchers during the BUILD and EARN |
| 34 | + stages. |
| 35 | +- **Top-Up Vouchers**: Future updates will allow direct top-ups via the |
| 36 | + dashboard. Currently, builders are redirected to Discord. |
| 37 | +- **Checking Voucher Balance**: Track your voucher balance and usage history. |
| 38 | + |
| 39 | +🧙🏼 [Go here](https://builder.iex.ec/) |
| 40 | + |
| 41 | +### Step 3: Grant Allowance (If Necessary) |
| 42 | + |
| 43 | +Use `iexec.account.approve(voucherAddress)` to authorize the voucher smart |
| 44 | +contract to debit your account if the voucher balance is insufficient. This |
| 45 | +ensures that if the voucher alone doesn't cover the execution cost, the |
| 46 | +remaining balance is automatically deducted from your account. |
| 47 | + |
| 48 | +For additional information on using xRLC for fallback payment in Web3Mail, refer |
| 49 | +to the **Using xRLC with Web3Mail** section. |
| 50 | + |
| 51 | +### Step 4: Execute Web3Mail's sendEmail Function |
| 52 | + |
| 53 | +When using a voucher for payment, set the `useVoucher` parameter to `true`: |
| 54 | + |
| 55 | +```ts twoslash |
| 56 | +import { IExecWeb3mail, getWeb3Provider } from '@iexec/web3mail'; |
| 57 | + |
| 58 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 59 | +const web3mail = new IExecWeb3mail(web3Provider); |
| 60 | +// ---cut--- |
| 61 | +const sendEmail = await web3mail.sendEmail({ |
| 62 | + protectedData: '0x123abc...', |
| 63 | + emailSubject: 'My email subject', |
| 64 | + emailContent: 'My email content', |
| 65 | + useVoucher: true, // [!code focus] |
| 66 | +}); |
| 67 | +``` |
| 68 | + |
| 69 | +## Using xRlC for Web3Mail |
| 70 | + |
| 71 | +If you choose to use xRLC to cover the computational cost of Web3Mail (or if you |
| 72 | +need to cover data access costs such as retrieving the recipient's email |
| 73 | +address), follow these steps: |
| 74 | + |
| 75 | +### Install the iExec SDK |
| 76 | + |
| 77 | +To manage RLC tokens, developers must use the iExec SDK, which offers all the |
| 78 | +necessary tools for interacting with the iExec platform. This includes |
| 79 | +depositing, withdrawing, and checking balances of RLC and xRLC |
| 80 | + |
| 81 | +- In your JS/TS project npm install iexec |
| 82 | +- Instantiate the iExec SDK (see the |
| 83 | + [doc](https://github.com/iExecBlockchainComputing/iexec-sdk/blob/master/docs/README.md#quick-start)) |
| 84 | + |
| 85 | +```javascript |
| 86 | +import { IExec } from 'iexec'; |
| 87 | +// connect injected provider |
| 88 | +const iexec = new IExec({ ethProvider: window.ethereum }); |
| 89 | +``` |
| 90 | + |
| 91 | +### Purchase RLC |
| 92 | + |
| 93 | +Obtain RLC tokens from a supported cryptocurrency exchange. |
| 94 | + |
| 95 | +### Convert to xRLC |
| 96 | + |
| 97 | +Use the iExec Bridge to convert your RLC into xRLC for use on iExec's sidechain. |
| 98 | +The bridging operation follows the lock & mint / burn & unlock principle. When |
| 99 | +sending tokens from Mainnet to Bellecour, the bridge locks the initial amount on |
| 100 | +the source chain and mints the equivalent on the destination chain. When going |
| 101 | +in the other direction, it burns tokens on the Sidechain and unlocks the same |
| 102 | +amount on Mainnet. The bridged asset is called xRLC on Bellecour. |
| 103 | + |
| 104 | +Users can send tokens from the Ethereum Mainnet to the iExec Sidechain or |
| 105 | +vice-versa using the Account Manager |
| 106 | +([iExec Explorer](https://explorer.iex.ec/bellecour) or |
| 107 | +[POA Bridge UI](https://bridge-bellecour.iex.ec/)) available across all iExec |
| 108 | +products. |
| 109 | + |
| 110 | +### Deposit xRLC |
| 111 | + |
| 112 | +Deposit the xRLC into your iExec account using the command: |
| 113 | + |
| 114 | +```javascript |
| 115 | +iexec.account.deposit(xRLC_amount); |
| 116 | +``` |
| 117 | + |
| 118 | +This converts xRLC into sRLC, used as proof of funds for task execution. |
| 119 | + |
| 120 | +### Check sRLC Balance |
| 121 | + |
| 122 | +Use the command below to check your balance: |
| 123 | + |
| 124 | +```javascript |
| 125 | +iexec.account.show(); |
| 126 | +``` |
| 127 | + |
| 128 | +### Execute sendEmail |
| 129 | + |
| 130 | +Set the `useVoucher` parameter to `false` when using Web3Mail's sendEmail |
| 131 | +function to pay with xRLC: |
| 132 | + |
| 133 | +```ts twoslash |
| 134 | +import { IExecWeb3mail, getWeb3Provider } from '@iexec/web3mail'; |
| 135 | + |
| 136 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 137 | +const web3mail = new IExecWeb3mail(web3Provider); |
| 138 | +// ---cut--- |
| 139 | +const sendEmail = await web3mail.sendEmail({ |
| 140 | + protectedData: '0x123abc...', |
| 141 | + emailSubject: 'My email subject', |
| 142 | + emailContent: 'My email content', |
| 143 | + useVoucher: false, // [!code focus] |
| 144 | +}); |
| 145 | +``` |
| 146 | + |
| 147 | +### Withdraw sRLC (If Desired) |
| 148 | + |
| 149 | +Convert sRLC back to xRLC and withdraw to your wallet using: |
| 150 | + |
| 151 | +```javascript |
| 152 | +iexec.account.withdraw(RLC_amount); |
| 153 | +``` |
0 commit comments