私链下智能合约的简单部署

用的是remix,以太坊部署在centos上,为了搞demo出来

当然,不准备用dapp形式,个人认为dapp的模型快凉了,而且以太币的价格即决定了dapp的成本,dapp的成本又反过来作用给以太币,以太坊的价格个人也不是很看好

废话不多少了
首先注意第一点,remix使用自己的provider的时候需要在geth的启动命令里加上

 --rpccorsdomain "https://remix.ethereum.org,http://remix.ethereum.org" 

具体原因remix也给打上标注了

1 随便编写一个代码

pragma solidity >=0.4.22 <0.7.0;
contract hello{
    string text="Hello World!";
     function say() view public returns (string memory) {
         return text;
     }
}

注意每个版本语法都不太一样
然后在compiler的detail里找到abi接口,复制下来
然后进行deploy,成功之后把地址也复制下来
然后直接调用就好了

var address="0x483bd93e3eeb56995620a1B1aFf9b44e8B183c78"
var abi=[
	{
		"inputs": [],
		"name": "say",
		"outputs": [
			{
				"internalType": "string",
				"name": "",
				"type": "string"
			}
		],
		"stateMutability": "view",
		"type": "function"
	}
]
var helloContract = new web3.eth.Contract(abi,address);
helloContract.methods.say().call().then(console.log)

你可能感兴趣的:(私链下智能合约的简单部署)