With Truffle
Truffle is a world-class development environment, testing framework and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier.

Setting up the development environment

There are a few dependencies to install before we start. Please install the following:
Do ensure that your npm modules have been added to your path
After installing the above dependencies, we can proceed to install truffle:
1
npm install -g truffle
Copied!
for more information on the different flags for npm-install
To verify that Truffle is installed properly, run this command:
1
truffle version
Copied!
Return (your version might differ):
1
Truffle v5.4.6 (core: 5.4.6)
2
Solidity v0.5.16 (solc-js)
3
Node v17.3.0
4
Web3.js v1.5.1
Copied!
If you're new to Truffle then please follow the Getting Started by truffle, To setup the truffle environment.

Initializing a truffle project

Initialize a truffle project:
1
truffle init
Copied!
Initialize a node project:
1
npm init -y
Copied!

truffle-config

  • After setting up your truffle project, be it cloning a repository or initializing a new truffle project
  • Open truffle-config.js
  • Edit truffle-config.js with f(x)Core network credentials
the file below is just a sample:
truffle-config.js
1
require('babel-register');
2
require('babel-polyfill');
3
const HDWalletProvider = require('@truffle/hdwallet-provider');
4
const fs = require('fs');
5
const mnemonic = fs.readFileSync(".secret").toString().trim();
6
7
8
module.exports = {
9
// See <http://truffleframework.com/docs/advanced/configuration>
10
// to customize your Truffle configuration!
11
// contracts_build_directory: path.join(__dirname, "client/src/contracts"),
12
networks: {
13
development: {
14
host: "127.0.0.1",
15
port: 7545,
16
network_id: "*" // Match any network id
17
},
18
fxtestnet: {
19
provider: () => new HDWalletProvider(mnemonic, 'https://testnet-fx-json-web3.functionx.io:8545'),
20
gasPrice: 4000000000000, //this is 4000 Gwei
21
network_id: 90001
22
},
23
24
},
25
26
contracts_directory: './src/contracts/',
27
contracts_build_directory: './src/abis/',
28
compilers: {
29
30
solc: {
31
version: "0.8.0",
32
settings: {
33
34
optimizer: {
35
enabled: true,
36
runs: 200
37
},
38
evmVersion: "petersburg"
39
}
40
}
41
}
42
};
Copied!
The key fields to note here are:
  • networks to include fxtestnet
  • provider to be set to any of our f(x)Core nodes, you may use the company's hosted node https://testnet-fx-json-web3.functionx.io:8545
  • gasPrice: 4000000000000
  • network_id: 90001
Notice, it requires mnemonic to be passed in for fxtestnet Provider, this is the seed phrase for the account you'd like to deploy from. Create a new .secret file in root directory and enter your 12 word mnemonic seed phrase to get started. To get the seed phrase from metamask wallet you can click into the Metamask icon-->Metamask Settings-->Security & Privacy-->Reveal Secret Recovery Phrase.

Deploying on f(x)Core Network

To request for Testnet FX click on this link
Run this command in root of the project directory:
1
truffle migrate --network fxtestnet
Copied!
Contract will be deployed on f(x)Core Testnet, it will look something like this:
1
2_deploy_contracts.js
2
=====================
3
4
Replacing 'MyContract'
5
-------------------
6
> transaction hash: 0x1be00a123a4751b25c71bf953a768051f5c518d21863637caa2d52b81bb8d44b
7
> Blocks: 1 Seconds: 5
8
> contract address: 0x5e7aC33b4811309bbeAe43212CA0719C450a2EaE
9
> block number: 551956
10
> block timestamp: 1640168723
11
> account: 0x2a9830C640d84fCeA5DF266cfEaA33428937F265
12
> balance: 1892.181296
13
> gas used: 255717 (0x3e6e5)
14
> gas price: 4000 gwei
15
> value sent: 0 ETH
16
> total cost: 1.022868 ETH
17
18
deploy done
19
20
> Saving migration to chain.
21
> Saving artifacts
22
-------------------------------------
23
> Total cost: 1.022868 ETH
24
25
26
Summary
27
=======
28
> Total deployments: 2
29
> Final cost: 1.567316 ETH
Copied!
Remember your address, transaction_hash and other details provided would differ, Above is just to provide an idea of structure.
Congratulations! You have successfully deployed HelloWorld Smart Contract. Now you can interact with the Smart Contract.
You can check the deployment status in our testnet explorer.