欢迎光临
黎跃春区块链技术博客

【Solidity智能合约开发第5篇】3分钟了解Solidity HelloWorld合约编写、编译、部署

一、HelloWorld合约编写

打开Atom新建一个文件HelloWorld.sol,编写如下合约代码。

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

contract HelloWorld {
  function helloWorld() external pure returns (string memory) {
    return "Hello, World!";
  }
}

二、Remix-IDE新建HelloWorld合约

打开Remix-IDE,新建HelloWorld.sol文件,将Atom里面编辑好的HelloWorld合约代码拷贝到里面,如下图所示例。

三、编译

四、查看字节码和ABI数据

  • BYTECODE
{
    "linkReferences": {},
    "object": "608060405234801561001057600080fd5b5061011e806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c605f76c14602d575b600080fd5b603360ab565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101560715780820151818401526020810190506058565b50505050905090810190601f168015609d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60606040518060400160405280600d81526020017f48656c6c6f2c20576f726c64210000000000000000000000000000000000000081525090509056fea26469706673582212200645f42c31932eab6ff03cf74f8203f2b2a8db8ffe801980f9cae10a9735504264736f6c63430006080033",
    "opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x11E DUP1 PUSH2 0x20 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH1 0xF JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH1 0x28 JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0xC605F76C EQ PUSH1 0x2D JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH1 0x33 PUSH1 0xAB JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 DUP1 PUSH1 0x20 ADD DUP3 DUP2 SUB DUP3 MSTORE DUP4 DUP2 DUP2 MLOAD DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP DUP1 MLOAD SWAP1 PUSH1 0x20 ADD SWAP1 DUP1 DUP4 DUP4 PUSH1 0x0 JUMPDEST DUP4 DUP2 LT ISZERO PUSH1 0x71 JUMPI DUP1 DUP3 ADD MLOAD DUP2 DUP5 ADD MSTORE PUSH1 0x20 DUP2 ADD SWAP1 POP PUSH1 0x58 JUMP JUMPDEST POP POP POP POP SWAP1 POP SWAP1 DUP2 ADD SWAP1 PUSH1 0x1F AND DUP1 ISZERO PUSH1 0x9D JUMPI DUP1 DUP3 SUB DUP1 MLOAD PUSH1 0x1 DUP4 PUSH1 0x20 SUB PUSH2 0x100 EXP SUB NOT AND DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP JUMPDEST POP SWAP3 POP POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH1 0x60 PUSH1 0x40 MLOAD DUP1 PUSH1 0x40 ADD PUSH1 0x40 MSTORE DUP1 PUSH1 0xD DUP2 MSTORE PUSH1 0x20 ADD PUSH32 0x48656C6C6F2C20576F726C642100000000000000000000000000000000000000 DUP2 MSTORE POP SWAP1 POP SWAP1 JUMP INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 MOD GASLIMIT DELEGATECALL 0x2C BALANCE SWAP4 0x2E 0xAB PUSH16 0xF03CF74F8203F2B2A8DB8FFE801980F9 0xCA 0xE1 EXP SWAP8 CALLDATALOAD POP TIMESTAMP PUSH5 0x736F6C6343 STOP MOD ADDMOD STOP CALLER ",
    "sourceMap": "58:119:0:-:0;;;;5:9:-1;2:2;;;27:1;24;17:12;2:2;58:119:0;;;;;;;"
}
  • ABI
[
    {
        "inputs": [
        ],
        "name": "helloWorld",
        "outputs": [
            {
                "internalType": "string",
                "name": "",
                "type": "string"
            }
        ],
        "stateMutability": "pure",
        "type": "function"
    }
]

五、部署

部署前0x855976084aC2cD1f7938f8f5fdd13F69203A36f8这个账号里面有100ETH,部署完毕后,只剩不到100,原因是因为部署合约需要消耗以太币。

赞(4) 打赏
未经允许不得转载:黎跃春区块链技术博客 » 【Solidity智能合约开发第5篇】3分钟了解Solidity HelloWorld合约编写、编译、部署

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

区块链在线课程、区块链职业技术水平认证考试一网打尽

区块链技术在线课程区块链技术职业认证

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏