this is an example of creating a swap asset (ERC20) contract with required Swapin
and Swapout
methods for cross chain bridge.
please ref. to crossChain-Bridge.
Normally, you may meed to modify the following items:
host
: the rpc host of the node
port
: the rpc port of the node
network_id
: the chain id
Add and modify contracts in contracts
directory.
like our example: BtcSwapAsset.sol.
Add an js
file to depoly contract in migrations
directory.
like our example: 2_deploy_contracts.js.
Use the following command to compile contracts:
truffle compile
or re-compile all contracts:
truffle compile --all
Use the following command to deploy contract:
truffle migrate
or re-deploy contract:
truffle migrate --reset
We may want to perform a test or 'dry run' migration firstly:
truffle migrate --dry-run
Because we need to build a raw contract creation transaction and sign this raw transaction using DCRM technology,
So we need the bytecode
as the transaction input data to build a raw contract cteation transaction.
bytecode
can be found in ./build/contracts/BtcSwapAsset.json
We can access the above deployed contract in truffle console terminal.
Firstly log into truffle console terminal:
truffle console
Then assign an variable app
to the deployed contract instance:
BtcSwapAsset.deployed().then(function(instance){ app = instance; })
For convenience, we can also assign all local accounts to accounts
variable:
web3.eth.getAccounts().then(function(result){ accounts = result })
Now we can access the methods and attributes of the deployed contract.
For example,
app.Swapout("45678","2MxQaHFhqKgYyTgcJj8foYHbPJQLQxvXQjp",{from:accounts[1]})
after attached to the running node, we can access the contract by the following infos:
app = eth.contract(abi).at(contractAddress)
abi
can be found in ./build/contracts/BtcSwapAsset.json
(after building)