基于区块链的毕业设计Jasmine Project Ethereum SDK – 茉莉花项目以太坊SDK

本文提供基于区块链的毕业设计国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,基于区块链的毕业设计Jasmine Project Ethereum SDK – 茉莉花项目以太坊SDK 是一篇很好的国外资料

Jasmine Project Ethereum SDK

Typescript Implementation

SDK

SDK wraps the interactions with TFC ERC20 Token contract on Ethereum. A detailed documentation can be found in docs

Install

Using npm:

npm install jasmine-eth-ts 

Or using yarn:

yarn add jasmine-eth-ts 

Usage

Import module:

import SDK, {Account, TFC} from "jasmine-eth-ts";

The entry point should SDK class. First thing to do is to construct an SDK object using an Ethereum endpoint (e.g. local private chain http://localhost:8545).

let sdk = new SDK("http://localhost:8545");

For testing purposes, we provide a MockEthereum class which wrapper ganache-core to provide a test environment to use SDK. Get the predefined accounts (each has 100 Ether) and endpoint:

let mockEth = new MockEthereum(); mockEth.predefinedPrivateKeys; mockEth.endpoint;

When using MockEthereum, you can create a new TFC ERC20 contract using:

let contractAddress = await sdk.deployTFC(initialTokenHolders, creator);

initialTokenHolders must be an array of length 20 of Accounts, who will split the initial 2 billion token supply evenly.

Using the sdk object, we can create a new Ethereum account:

let account: Account = sdk.createAccount();

Or retrieve an existing account using private key:

let account: Account = sdk.retrieveAccount(privateKey);

We can set a default account for the sdk object to interact with Ethereum:

sdk.setDefaultAccount(account);

Now a TFC object can be constructed using its address of contract:

let tfc: TFC = sdk.getTFC(contractAddress, account);

The second parameter of getTFC() is optional, which is the default account for the tfc object to interact with Ethereum. If omitted, the default account of tfc object will be use the same one as sdk object.

Now with the tfc object, we can directly interact with smart contract:

let balance = await tfc.balanceOf(account.address); // get token balance await tfc.transfer(anotherAccount.address, new BN(10)); // transfer 10 tokens from default account to anotherAccount 

More APIs can be found in the documentation.


Jasmine Project以太坊ethSDK

Typescript实现

SDK

SDK在以太坊eth上封装了与TFC ERC20令牌契约的交互。使用npm:

Install

或使用yarn:

npm install jasmine-eth-ts 

导入模块:

yarn add jasmine-eth-ts 

Usage

入口点should SDK类可以在docs中找到详细的文档。首先要做的是使用以太坊eth端点(例如本地私有链)构造一个SDK对象http://localhost:8545)。

import SDK, {Account, TFC} from "jasmine-eth-ts";

出于测试目的,我们提供了一个MockEthereum类,该类包装了ganache内核,以提供使用SDK的测试环境。获取预定义的帐户(每个帐户有100个以太)和终结点:

let sdk = new SDK("http://localhost:8545");

使用MockEthereum时,可以使用:

let mockEth = new MockEthereum(); mockEth.predefinedPrivateKeys; mockEth.endpoint;

initialTokenHolders必须是一个长度为20个帐户的数组,这些帐户将平均分配最初的20亿个代币供应。

let contractAddress = await sdk.deployTFC(initialTokenHolders, creator);

使用sdk对象,我们可以创建一个新的以太坊eth帐户:

或使用私钥检索现有帐户:

let account: Account = sdk.createAccount();

我们可以为sdk对象设置一个与以太坊eth交互的默认帐户:

let account: Account = sdk.retrieveAccount(privateKey);

现在可以使用其协定地址构造TFC对象:

sdk.setDefaultAccount(account);

getTFC()的第二个参数是可选的,它是tfc对象与以太坊eth交互的默认帐户。如果省略,tfc对象的默认帐户将与sdk对象使用相同的帐户。

let tfc: TFC = sdk.getTFC(contractAddress, account);

现在有了tfc对象,我们可以直接与智能合约交互:

更多API可以在文档中找到。

let balance = await tfc.balanceOf(account.address); // get token balance await tfc.transfer(anotherAccount.address, new BN(10)); // transfer 10 tokens from default account to anotherAccount 

More APIs can be found in the documentation.

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/17567.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » 基于区块链的毕业设计Jasmine Project Ethereum SDK – 茉莉花项目以太坊SDK

提供最优质的资源集合

立即查看 了解详情