美文网首页
using truffle and geth to compil

using truffle and geth to compil

作者: zouxiaoyu | 来源:发表于2018-01-12 14:58 被阅读0次

    try to deploy the contract into the Rinkeby network.

    geth, truffle.

    1. using vim to edit a solidity contract.

    2. add a entry of Rinkeby into the truffle.js, so truffle can connect to the Rinkeby network. code:

    rinkeby: {

    host: "127.0.0.1",

    port: 8545,

    from:"any account address for default deployment",

    network_id: "4",// Match Rinkeby

    gas:4612388

    }

    3. truffle compile

    4. add a migration file into the migrations dir

    5. truffle migrate --network rinkeby

    before 5) need to start geth and unlock your account:

    geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --unlock="your account address"

    Details can be referred to 

    https://blog.abuiles.com/blog/2017/07/09/deploying-truffle-contracts-to-rinkeby/

    When to interact with a deployed contract on Rinkeby, try the following steps:

    0. u need to get the ABI and address of the deployed contract.

    u can search them on the etherscan website (https://rinkeby.etherscan.io/ for rinkeby)

    If you want to interact with your own contract, then you need to verify your contract with source code first. By doing so you can obtain the ABI (remember to export as Json format). 

    When you verify your contract, the website may ask you to provide the complier version (I find that although we declare the compiler version in the contract, the truffle seems to use its own version to compile it....So what is the point in declaring version in the code...), if you cannot decide the truffle default version, you can go the build dir and find the built file to find the version value. Or, I think you can also directly use truffle version to get the compiler version. Any way, try.

    1. After you get the ABI and the address of the contract that you want to interact with through geth, you then can use them to get an instance of the contract, after that, you can call its functions.

    abi=[xxx]; the xxx is the exported Json format of ABI.

    // creation of contract object

    var MyContract = web3.eth.contract(abi);

    // initiate contract for an address

    var myContractInstance = MyContract.at("contract address");

    // call constant function

    var result = myContractInstance.myConstantMethod('myParam');

    console.log(result) // '0x25434534534'

    相关文章

      网友评论

          本文标题:using truffle and geth to compil

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