Ethereum

With SimpleID, you have full Ethereum access from within the server environment.

Deploying Smart Contracts

As a developer, you probably know how to deploy a smart contract. But what if you want to allow your users to deploy smart contracts in your application? SimpleID makes that possible.

First, you'll need to build up the contract the user wants to deploy:

const payload = {
email: userEmail,
fromEmail: "hello@simpleid.xyz",
bytecode,
abi,
account
}
const contract = await simple.createContract(payload);

The payload above includes the user's email, the contract bytecode, the contract abi, and the user's Ethereum account address. Calling this function will store the contract transaction with SimpleID and send the user an email asking them to approve the transaction.

Once the user has received the one-time code to approve the contract deployment, you'll need to take in that code and pass it to another function like this:

const payload = {
email: userEmail,
code
}
const contract = await simple.deployContract(payload);

The payload when deploying the contract takes far fewer parameters. You'll need the user's email and the one-time code supplied by the user.

The response from this function, if successful, includes a transaction hash. This hash will be useful, so it is recommended that you record it somewhere.

Once the contract is deployed, it will need to be mined. Depending on the network you've configured, it could take some time. You can listen for when the contract is mined or periodically check by using the utility function: simple.pollForStatus(tx)

Interacting with smart contracts

Your users can interact with a deployed contract on the network you've specified similar to how they'd interact with smart contracts using other services. Let's first explore how a contract is fetched:

const contract = await simple.fetchContract(abi, contractAddress);

You'll need to pass in the contract ABI and the contract address in order to fetch the contract. Keep in mind if you pass in the ABI and address of a contract deployed on a network that differs from the one you specified when initializing SimpleID, you'll need to re-initialize.

You can call read-only methods on the contract by tacking on the contract method to the end of the variable that holds the contract. For example:

const contract = await simple.fetchContract(abi, address);
const taskCount = await contract.taskCount();

When you're ready to allow a user to call a non-static method, you'll need to build up the contract transaction for approval, similar to what you did when building up the contract deployment transaction.

const params = {
method: "createUser",
abi,
email,
value: "John", //For multiple variables, wrap in array: ["John", "123 Main St"]
address: contractAddress
}
const approval = await simple.createContractTransaction(params);

There are some important parameters being passed to this function, so let's break them down one by one.

Contract Deployment Parameters

Parameter

Purpose

method

This is the smart contract method or function name you are calling.

abi

The contract abi.

email

Your user's email.

value

This is the data to be passed to the contract method. It's important to note that if your contract expects multiple variables to be passed, you'll need to wrap them in an array like this: ["John", "123 Main Street"]

address

This is the smart contract address.

Once this function is called, the transaction will be stored with SimpleID and a one-time code will be sent to the user to approve the transaction. When the user supplies that code back to your application, you can execute the transaction like so:

const payload = {
email: simple.getUserData().email,
contractTx: true,
code
}
const transaction = await simple.broadcastTransaction(payload);

There are non-contract transactions that can be broadcast, so be sure to specify contractTx as true.

As with deploying a contract, the speed at which the contract transaction is mined will depend on the network you chose to use for your application. If you'd like to poll for the transactions mining status, you call simple.pollForStatus(tx).

Sending non-contract transactions

SimpleID supports non-contract transactions as well, but the documentation for this is still under construction. Stay tuned!