2.6 - Ethereum

作者: 空乱木 | 来源:发表于2019-08-23 00:07 被阅读1次

原文链接:https://docs.simpleid.xyz/javascript-sdk/ethereum

Ethereum模块可用于身份验证和智能合约。如果不启用身份验证模块,则不可能使用智能合约模块。

Authentication 身份验证

当使用Ethereum进行身份验证时,将代表用户初始化钱包。由于SimpleID是一个托管解决方案,所以该钱包将由SimpleID托管,但是对钱包的访问将严格依赖于用户的密码。

如果您使用Ethereum身份验证,欢迎您以任何您认为合适的方式使用返回的数据。创建/登录帐户后返回的对象应该是这样的:

{
message: "successfully created account",
body: {
appConfig: {}, //Object with the config information you supplied as part of account creation
store: {
sessionData: {} //Object with your actual user info. There will be a nested object called userData
}
}
}

要访问返回的用户信息,需要像这样深入到对象中returnedObject.body.store.sessionData.userData.

Smart Contracts 智能合约

SimpleID支持创建和执行智能合约。

Deploying a contact 部署合约
import { createContract } from 'simpleid-js-sdk`;

const params = {
  username, //your user's username
  password, //your user's password
  devId: ${yourDeveloperId}, //available in your dev account user interface
  apiKey: ${yourSimpleIDAPIKey}, //available in your dev account user iterface
  abi, //the abi you/your user created in building the smart contract
  bytecode //the compiled bytecode from solidity
}

const contract = await createContract(params);
console.log(contract);
Fetching a contract 获取合约
import { fetchContract } from 'simpleid-js-sdk`;

const params = {
  contractAddress, //the address from the originally deployed contract
  devId: ${yourDeveloperId}, //available in your dev account user interface
  apiKey: ${yourSimpleIDAPIKey}, //available in your dev account user iterface
  abi, //the abi you/your user created in building the smart contract
}

const contract = await fetchContract(params);
console.log(contract);

注意:
到目前为止,所有的合约创建和支持都在ropsten testnet上。这在未来将会改变,但是对于SimpleID对Ethereum支持的早期采用和测试来说,这是最有意义的。

相关文章

网友评论

    本文标题:2.6 - Ethereum

    本文链接:https://www.haomeiwen.com/subject/yeuasctx.html