码迷,mamicode.com
首页 > Windows程序 > 详细

etherlime-2-Etherlime Library API-deployer

时间:2018-12-06 15:57:11      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:struct   win   style   VID   config   something   默认   cti   ...   

Etherlime Library API 库API

Deployer部署者

Deployer functionality

The main functionality the deployer exposes is (obviously) the ability to deploy compiled contract.

开发者暴露的主要函数(明显)是部署编译合约的能力。

This is achieved through the deploy(contract, [libraries], [params]) function.

通过deploy(contract, [libraries], [params])函数得到这样的能力

 

deploy(contract, [libraries], [params])

Parameters参数:

  • contract - descriptor object for contract to be deployed. More details below被部署合约的描述对象,更多细节在下面
  • libraries - key-value object containing all libraries which will be linked to the contract. 链接到合约的包含所有库的键-值对象
  • params - the constructor params you’d need to pass on deploy (if there are any) 在部署中你需要传给合约构造函数的参数(如果需要的话)

The contract is descriptor object that needs to have at least the following three fields:

合约是至少需要下面三个字段的描述对象

  • contractName - the name of the contract 合约名字
  • abi - the abi interface of the contract 合约abi接口
  • bytecode - the compiled bytecode 编译的字节码

The easiest way to get such descriptor is to compile your solidity files via etherlime compile

最简单的得到描述者的方法是通过etherlime compile编译你的solidity文件

The libraries object should be in the following format:

文件对象应该是如下的格式:

{
    libraryName0: 0xAddressOfLibrary0,
    libraryName1: 0xAddressOfLibrary1
}

If the contract to be deployed doesn’t contains any libraries, {}, undefined, null, false or 0 can be passed. For convenience we have made the deploy function to work even without this parameter passed.

如果被部署的合约没有包含任何的库,那么可以传递{}, undefined, null, false0给库对象。为了方便,即使没有这些参数被传递我们也可以让部署函数工作起来

Example举例说明:

Linking libraries链接库

const contractUsingQueueAndLinkedList = require(...);

const libraries = {
    Queue: 0x655341AabD39a5ee0939796dF610aD685a984C53,
    LinkedList: 0x619acBB5Dafc5aC340B6de4821835aF50adb29c1
}

await deployer.deploy(contractUsingQueueAndLinkedList, libraries);

Skipping linking on contract without arguments

跳过库链接并且合约构造函数不需要参数

const contractWithoutLibraries = require(...);

await deployer.deploy(contractWithoutLibraries);

Skipping linking on contract with arguments

跳过库链接,合约构造函数需要参数

const contractWithoutLibraries = require(...);

await deployer.deploy(contractWithoutLibraries, false, param1, param2);

 

estimateGas(contract, [libraries], [params])估计使用的gas

Estimates the gas that this transaction is going to cost you.估计这个交易将要花费的gas

Parameters参数:

  • contract - descriptor object for contract to be deployed 部署的合约的描述对象
  • libraries - key-value object containing all libraries which will be linked to the contract. 链接到合约的包含所有库的键-值对象
  • params - the constructor params you’d need to pass on deploy (if there are any)在部署中你需要传给合约构造函数的参数(如果需要的话)

The contract is descriptor object is the same as above.

合约是和上面一样的描述对象

Example举例说明

const estimate = await deployer.estimateGas(TestContract, randomParam1, randomParam2);
// returns something like "2470692"

 

Deployers

InfuraPrivateKeyDeployer

InfuraPrivateKeyDeployer(privateKey, network, apiKey, [defaultOverrides])

Parameters参数:

  • privateKey - The private key to the deployment wallet 部署钱包的密钥
  • network - network as found in ethers.providers.networks 使用ethers.providers.networks找到的网络
  • apiKey - your Infura API key
  • defaultOverrides - [Optional] object overiding the deployment settings for gasPrice and gasLimit.(可选)复写部署设置中的 gasPriceasLimit的对象
const etherlime = require(etherlime);

const TestContract = require(./TestContract.json);

const defaultConfigs = {
    gasPrice: 20000000000,
    gasLimit: 4700000
}

const deploy = async (network, secret) => {

    const deployer = new etherlime.InfuraPrivateKeyDeployer(Your Private Key Goes Here, ropsten, Your Infura API Key, defaultConfigs);

    const result = await deployer.deploy(TestContract, 0xda8a06f1c910cab18ad187be1faa2b8606c2ec86, 1539426974);
}

 

JSONRPCPrivateKeyDeployer

JSONRPCPrivateKeyDeployer(privateKey, nodeUrl, [defaultOverrides])

Parameters参数:

  • privateKey - The private key to the deployment wallet部署钱包的密钥
  • nodeUrl - the url to the node you are trying to connect (local or remote)你打算连接的节点的URL(本地或远程)
  • defaultOverrides - [Optional] object overiding the deployment settings for gasPrice and gasLimit.(可选)复写部署设置中的 gasPriceasLimit的对象
const etherlime = require(etherlime);

const TestContract = require(./TestContract.json);

const defaultConfigs = {
    gasPrice: 20000000000,
    gasLimit: 4700000
}

const deploy = async (network, secret) => {

    const deployer = new etherlime.JSONRPCPrivateKeyDeployer(Your Private Key Goes Here, http://localhost:8545/, defaultConfigs);

    const result = await deployer.deploy(TestContract);
}

 

EtherlimeGanacheDeployer

EtherlimeGanacheDeployer([privateKey], [port], [defaultOverrides])

Parameters:

  • privateKey - [Optional] The private key to the deployment wallet. Defauts to the first one in the etherlime ganache(可选)部署钱包的私钥。默认为etherlime ganache中的第一个账户
  • port - [Optional] the port you’ve ran the etherlime ganache on. Defaults to 8545.(可选)etherlime ganache的端口,默认为8545
  • defaultOverrides - [Optional] object overiding the deployment settings for gasPrice and gasLimit.(可选)复写部署设置中的 gasPriceasLimit的对象

This deployer only works with etherlime ganache

该部署只在etherlime ganache能工作

const etherlime = require(etherlime);

const TestContract = require(./TestContract.json);

const defaultConfigs = {
    gasPrice: 20000000000,
    gasLimit: 4700000
}

const deploy = async (network, secret) => {

    const deployer = new etherlime.EtherlimeGanacheDeployer();

    const result = await deployer.deploy(TestContract);
}

 

 

etherlime-2-Etherlime Library API-deployer

标签:struct   win   style   VID   config   something   默认   cti   ...   

原文地址:https://www.cnblogs.com/wanghui-garcia/p/10072337.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!