-
Notifications
You must be signed in to change notification settings - Fork 33
Deploy smart contract using remix
If you have no problem of running online Remix IDE (https://remix.ethereum.org), you can ignore this step and operate directly on the online Remix IDE.
Firstly we need install remixd
:
npm install remixd -g
then we install remix-ide
through source code:
git clone https://github.com/ethereum/remix-ide.git
cd remix-ide
git checkout -b v0.9.4 v0.9.4
Because solc's version may be too higher, we need modify it to a lower version. We choose v0.5.12
here, but v0.5.4
is most tested.
Replace line in package.json
:
"downloadsolc_root": "wget --no-check-certificate https://solc-bin.ethereum.org/bin/soljson-v0.6.1+commit.e6f7d5a4.js -O soljson.js",
with the following line:
"downloadsolc_root": "wget --no-check-certificate https://solc-bin.ethereum.org/bin/soljson-v0.5.12+commit.7709ece9.js -O soljson.js",
Then run
npm install
npm start
to install and run remix-ide
.
Open in browser the URL: http://127.0.0.1:8080. It may take a few minutes to load the content.
We should activate at least two modues: Solidity compiler
and Deploy & run transactions
.
In our example, we add file FSNExample.sol
and input the contract content. Please reference to FIP-0001-Smart-contract-support-timelock-and-asset for more info about this contract.
FSNExample.sol
pragma solidity <=0.5.12;
contract FSNContract {
address constant precompile = address(0x9999999999999999999999999999999999999999);
// these events will be generated by the low level impl.
event LogFusionAssetReceived(bytes32 indexed _asset, address indexed _from, uint256 _value, uint64 _start, uint64 _end, SendAssetFlag _flag);
event LogFusionAssetSent(bytes32 indexed _asset, address indexed _to, uint256 _value, uint64 _start, uint64 _end, SendAssetFlag _flag);
enum SendAssetFlag {
UseAny, // 0
UseAnyToTimeLock, // 1
UseTimeLock, // 2
UseTimeLockToTimeLock, // 3
UseAsset, // 4
UseAssetToTimeLock // 5
}
function _sendAsset(bytes32 asset, address to, uint256 value, uint64 start, uint64 end, SendAssetFlag flag) internal returns (bool, bytes memory) {
bytes memory input = abi.encode(1, asset, to, value, start, end, flag);
return precompile.call(input);
}
}
contract FSNExample is FSNContract {
address owner;
modifier onlyOwner {
require(msg.sender == owner, "only owner");
_;
}
constructor() public {
owner = msg.sender;
}
// If a contract want to receive Fusion Asset and TimeLock from an EOA,
// the contract must impl the following 'receiveAsset' interface.
function receiveAsset(bytes32 assetID, uint64 startTime, uint64 endTime, SendAssetFlag flag, uint256[] memory extraInfo) payable public returns (bool success) {
(assetID, startTime, endTime, flag, extraInfo); // silence warning of Unused function parameter
return true;
}
// impl by calling a precompiled contract '0x9999999999999999999999999999999999999999'
// which support send out Fusion Asset and TimeLock from the calling contract.
function sendAsset(bytes32 asset, address to, uint256 value, uint64 start, uint64 end, SendAssetFlag flag) onlyOwner public returns (bool success) {
(success,) = _sendAsset(asset, to, value, start, end, flag);
require(success, "call sendAsset failed");
return true;
}
}
Compile steps:
-
Select
Solidity compiler
tab page -
Set compiler version to 0.5.12
-
Click
Compile FSNExample.sol
button to compile the source code.
In our example, we want deploy smart contract on Fusion private blockchain. So we need start efsn node at first.
Start Fusion private chain with RPC port 12001
:
./efsn --devnet --datadir node1 --port 12341 --rpc --rpcport 12001 --rpcapi web3,eth,net,db,personal,fsn,fsntx --rpcaddr 0.0.0.0 --rpccorsdomain "*" --ws --wsport 13001 --wsapi web3,eth,net,db,personal,fsn,fsntx --wsaddr 0.0.0.0 --wsorigins "*" --unlock 0x0122bf3930c1201a21133937ad5c83eb4ded1b08 --password passwd --miner.etherbase 0x0122bf3930c1201a21133937ad5c83eb4ded1b08 --networkid 55555 --mine --autobt --gcmode archive 2>&1 |tee -a node1.log
Please reference to Deploy-private-chain for more information.
Deploy steps:
-
Select
Deploy & run transactions
tab page. -
Set environment to web3 provider and set
Web3 Provider Endpoint
tohttp://localhost:12001
(12001
is my node's RPC port, see above) -
Choose
FSNExample
contract and clickDeploy
button to deploy.
The log window will show the contract creation
transaction details.
Fill parameters to call receiveAsset
method and click transact
button to send transaction.
params:
assetID: asset ID
startTime: start time, 0 means now
endTime: end time, 0 means forever
flag: flag to control how to spend timelock and asset
extraInfo: extra info for concrete contract logic
Notice: do not forget to fill Value
and take care of its unit. Its position is under Gas limit
field, and above Deploy
button.
The log window will show the receiveAsset
transaction details.
Fill parameter to call sendAsset
method and click transact
button to send transaction.
params:
asset: asset ID
to: receiver address
value: send amount with unit of Wei
start: start time, 0 means now
end: end time, 0 means forever
flag: flag to control how to spend timelock and asset
The log window will show the sendAsset
transaction details.