Deploy Smart Contract
Now you are ready to develop & deploy smart contract on MEVerse. We have used Truffle as an example, as it is the most widely used tool.
Create Project Directory
First, create a directory to store the source code
$ mkdir meverse-test
$ cd meverse-test
Initialize Truffle
To deploy contract, initialize Truffle
$ truffle init
Write simple solidity contract
Create MEVerseGreeter.sol
at meverse-test/contracts
directory
$ cd contracts
$ touch MEVerseGreeter.sol
$ vi MEVerseGreeter.sol
Write following code in MEVerseGreeter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.6;
contract Mortal {
/* Define Variable owner of the type address */
address payable owner;
/* This function is executed at initialization and sets the owner of the contract */
constructor () public { owner = msg.sender; }
/* Function to recover the funds on the contract */
function kill() public payable { if (msg.sender == owner) selfdestruct(owner); }
}
contract MEVerseGreeter is Mortal {
/* Define variable greeting of the type string */
string greeting;
/* This runs when the contract is executed */
constructor (string memory _greeting) public {
greeting = _greeting;
}
/* Main function */
function greet() public view returns (string memory) {
return greeting;
}
}
Modify Migration Script
Deploy contract with hdwallet-provider. Install the library first.
$ npm install @truffle/hdwallet-provider
you can also deploy contracts written via Truffle's Dashboard, please refer to the Dashboard for more details.
Use Truffle Dashboard : https://trufflesuite.com/docs/truffle/how-to/use-the-truffle-dashboard/
Modify MEVerse Testnet network information at truffle-config.js
// truffle-config.js
const HDWalletProvider = require("@truffle/hdwallet-provider");
...
networks: {
MEVerseTestnet: {
provider: () =>
new HDWalletProvider({
privateKeys: [
"adf...583a9", // 컨트랙트를 배포할 계정 private key
],
providerOrUrl: "https://rpc.meversetestnet.io",
}),
network_id: 4759, // MEVerse testnet chain id
}
}
Deploy Smart Contract with Truffle
$ truffle migrate --network MEVerseTestnet
Compiling your contracts...
===========================
> Compiling ./contracts/MEVerseGreeter.sol
> Artifacts written to /truffle_sample/build/contracts
> Compiled successfully using:
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang
Starting migrations...
======================
> Network name: 'MEVerseTestnet'
> Network id: 4759
> Block gas limit: 30000000 (0x1c9c380)
1_initial_migration.js
======================
Deploying 'MEVerseGreeter'
--------------------------
> transaction hash: 0xe1f6fad3f5121cb1448750113f25e20228c4b9e800d0a7cda8ca04ff464257f2
> Blocks: 0 Seconds: 0
> contract address: 0xeb7A1483E3408Af19231262643672719CcFc6E17
> block number: 27778152
> block timestamp: 1668760128889501
> account: 0x19368fCd2F0EE8d2C788b754F6504FD49de449E7
> balance: 191907.1
> gas used: 223381 (0x36895)
> gas price: 1000 gwei
> value sent: 0 ETH
> total cost: 0.223381 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.414624 ETH
Summary
=======
> Total deployments: 1
> Final cost: 0.414624 ETH
Last updated