win 7系统web3j部署调用智能合约

首先我们要有一个完整的solidity智能合约文件 token.sol

1.安装solc:https://solidity.readthedocs.io/en/develop/installing-solidity.html

npm install -g solc

2.安装web3j环境:https://docs.web3j.io/command_line.html

3.编译合约: solc token.sol --bin --abi --optimize -o .  (亲测win7下 solc换成 solcjs)

4.生成JAVA类:  web3j solidity generate --javaTypes token.bin token.abi -o . -p token.java

5.

private static BigInteger gasLimit = new BigInteger("1000000");
private static BigInteger gasPrice = new BigInteger("15000000000");

public static void main(String[] args) throws Exception {
    Web3j web3j = Web3j.build(new HttpService(Environment.RPC_URL_ropsten));
    BigInteger initialSupply = new BigInteger("10000");
    String tokenName = "token1";
    String tokenSymbol = "TOKEN1";
    //String addr = "addr";
    Credentials credentials = Credentials.create("privatekey");
    Token_sol_TokenERC20 token = Token_sol_TokenERC20.deploy(web3j, credentials, gasPrice, gasLimit, initialSupply, tokenName, tokenSymbol).send();
    System.out.println(token.getContractAddress());
}

猜你喜欢

转载自blog.csdn.net/qq_35420123/article/details/81806411