using truffle and geth to compile and deploy a contract

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'

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容