Usage

How to use Shipl-Meta in your dApp.

Preparation

Before attempting to integrate, you'll need to create an account in Shipl's console. Head on over to console.shipl.co to create it to start this process.

After a short time, you should receive an email into your account, click on the link, you will follow a tutorial to create your first app.

Metamask Quick Start

In this first example, we'll show the Shipl SDK being used as a meta-transaction provider for your customers. We'll require the customer use Metamask to authenticate and verify their phone number. After sign-in, they will be able to process "etherless" transactions.

This example uses the "rinkeby" environment over at testnet.api.shipl.co. In this example you will replace "YOUR_SHIPL_APP_ID" with the "appID" created in your Shipl account.

import Shipl from 'shipl';
const shipl = new Shipl({
web3Provider: window.web3, // you can also load the sdk with a privateKey
network: 'rinkeby', // we support kovan, ropsten and mainnet
appId: 'YOUR_SHIPL_APP_ID'
})

Then you will have to call the "login" method with a callback to enable the Shipl SDK to ask the user his phone number and then for the verification code send by SMS. For example on node.js you can use readline-sync. The verification happen only one time when the user submit a transaction for the first-time through Shipl. Because we create a proxy contract for every users. The "identity" variable correspond to the user's proxy contact for the selected network. The "deviceKey" variable is equal to the user's address stored in his Metamask.

The "deviceKey" is the signer of the transaction, always use the "identity" value for the call of your functions which need the identity in argument.

Thanks to the creation of a proxy contract for every users, you don't need to change a single line into your smart contract, they can stay the same. We are fully compatible with the method "msg.sender" in solidity.

const { identity, deviceKey } = await shipl.login(readline.question)

Because Shipl is a web provider, your next step is to pass the Shipl SDK into any web3 compatible library.

const web3 = new Web3(shipl.getProvider())

Then you call you smart contract in the regular web3 way.

const contract = new web3.eth.Contract(abi, contractAddress);
contract.methods.register(identity, 1) // we use the identity to represent the user
.send({
from: deviceKey // we use the deviceKey to sign the transaction
})
.on('transactionHash', transactionHash => {
console.log('This the transactionHash', transactionHash);
});

Finally we can get the internal transaction datas.

await shipl.getInternalTransactionsData(abi, txHash)

In a near future we will provide these informations directly into the transaction logs of the provided by web3.

Examples

You have node.js and a browser implementation example available in the /examples folder of our Shipl SDK.