đCOTI V2 Quickstart
This quick start guide will help developers get started with deploying smart contracts onto the COTI network. If you are already familiar with Ethereum, EVM-related technologies, smart contracts and web3, follow the steps below to get started.
You should already be familiar with concepts such as Ethereum, EVM, and Smart Contracts.
If you are new to Ethereum and smart contracts, the following introductory guides are a great place to get started:
For questions & support join our Discord!
Useful links
SDKs | Examples | Network Info |
---|---|---|
If you'd like to learn more about COTI's progression, read COTI's evolution from V1 to V2. To get familiar with some of the core concepts of blockchain privacy, get started with the Introduction section.
Network Info
You can view COTI network information on the Networks page. To add it to the networks of your wallet application you can use one the following sites:
NOTE:
EOA Wallets such as MetaMask may display a warning about COTI Testnet being a potential scam. This is due to the COTI token existing as an ERC-20 token on Ethereum and using the same token name on COTI Testnet. We're working with wallet providers to fix this issue.
The COTI Testnet is currently operating in review mode. As such, it may experience unplanned resets. Remember to back up your work regularly and avoid storing any sensitive or confidential data.
Native Transfer
The following process will help you deploy the native_transfer.py
example from the COTI Python SDK Examples project. This script will transfer native funds from your wallet account to a random wallet. It will also:
Create a EOA (Externally Owned Account)
Validate minimum balance
Ensure your environment meets all the pre-requisites. Visit the pre-requisites section of the readme. Alternatively, use an editor like PyCharm to take care of the pre-requisites for you.
Clone the Python examples repo along with its submodules into your desired location
Change directory to the newly create one
Install the project's requirements
Set the python path as following
Run the
native_transfer.py
scriptRunning the script will automatically create an account and a key/value pair with name:
ACCOUNT_PRIVATE_KEY
(visible in the.env
file). The script will output something like this:It is normal to receive the exception
Not enough balance!
on the first run. This will be resolved once the account is funded.Head to the faucet at https://faucet.coti.io to get devnet funds. Send the following message to the BOT using your newly created
account address
:devnet <account address>
The bot will reply with the message:<username> faucet transferred 5 COTIv2 (devnet)
Run the
native_transfer.py
script once moreThe script will output as following:
Now that your account is created and funded, you can now onboard the account to get your new network key.
On-board Account
The following process will help you deploy the onboard_account.py
example from the COTI Python SDK Examples repo. This script onboards an EOA into the network. It will also:
Trigger the network to create a unique AES key for the user
Encrypt the unique user-specific AES key using the Public key so that its value can be viewed only by the EOA owner.
This is a mandatory script for any operation executed in any contract requiring encrypt/decrypt operations which are part of the new EVM precompiles actions.
Run the
onboard_account.py
scriptRunning the script will automatically create an account and an
ACCOUNT_ENCRYPTION_KEY
(visible in the.env
file as well as the output). The script output will look something like this:This encryption key is sensitive. Ensure it is not uploaded to public places and keep it safe. This key is produced per EOA wallet, meaning a unique wallet/EOA combination will have a unique encryption key.
The
.env
file will also have other useful information, such as the node address, websocket address, and the contract directories. Now that the account is onboarded, let's deploy a contract on-chain.
Deploy Data On-Chain
The following process will help you deploy the data_on_chain.py
example from the COTI Python SDK Examples repo. As its name suggests, the contract will compile and deploy the corresponding DataOnChain.sol
contract, located in the confidentiality-contracts
directory.
This contract can be used in order to browse and get a feel of the COTI network. The contract allows for the secure handling of encrypted data, enabling storage, transformation, and arithmetic operations on encrypted values using the MpcCore
library. It supports operations where values are encrypted using both network and user keys, ensuring data privacy and security on-chain.
Navigate to the
examples
directory in theconfidentiality-contracts
directory inside thecoti-sdk-python-examples
project.Run the
data_on_chain.py
scriptRunning the script will deploy the contract and output the address where the contract was deployed. The script output will look something like this (with some omitted block hashes at the end of ther response):
The deployment will include the transaction data as well as the address the contract was deployed to:
You can now view the contract on devnet explorer using the following convention:
https://explorer-devnet.coti.io/address/<contract deployment address>
In our case: https://explorer-devnet.coti.io/contract/0x91af1cd8bbc3b7dccd5ff19f522cd9a49067f928
Let's note the following facts about the contract and the script:
When the contract was deployed, the
uint64 private clearValue
variable was assigned a value of5
as evidenced by lines 15-17 of the contract:The function
getSomeValue
of the contract will then return the value ofclearValue
The function
basic_get_value
of the python script is making sure the value was set as expected.
Now let's take a look on at the basic flow that sends a clear value, encrypts it, and decrypts it.
The python function
basic_clear_encrypt_decrypt
initiates the process, calling other functions as necessary.The python function
save_clear_value_network_encrypted_in_contract
is used to pass a clear value from the user.Once the value is populated, the script will call the Solidity contract and use its
setSomeEncryptedValue
function. This function in turn callssetPublic64
from theMpcCore
library, which turns the value into GarbledText and then into CipherText using the network key. This value is now encrypted in a network block.In order to validate the block had a ClearText input, the block details from the transaction are extracted using the
validate_block_has_tx_input_encrypted_value
function.The value is then encrypted using the function
save_network_encrypted_to_user_encrypted_input_in_contract
, this function saves the network-encrypted value to the user-encrypted input in the contract.The encrypted value is retrieved from the contract using the function
get_user_encrypted_from_contract
to ensure the encrypted value can be successfully retrieved with the user's AES key.
Last updated