-
Notifications
You must be signed in to change notification settings - Fork 114
Smart Contract
QuarkChain runs EVM on each shard and thus supports all Ethereum smart contract bytecode compiled from Solidity.
Similar to Ethereum, to build a contract deployment transaction leave the to
field empty and put the byte code in the data
field. A smart contract is always deployed to a specific shard decided by toFullShardId
in the transaction.
fromFullShardId
and toFullShardId
must map to the same shard in order to succeed. The FULL_SHARD_ID
of the contract address created will be the same as toFullShardId
. Normally you should just set toFullShardId
the same as fromFullShardId
.
A couple of comments on smart contract deployment:
- If a user does not have any balance on the shard where the contract is to be deployed, a user must manually get sufficient balance from either 1) user’s balance of another shard via cross-shard transaction or 2) another user's balance. In the future, case 1) will be automatically handled by a smart wallet.
- If a smart contract calls another smart contract in the shard, both caller and callee smart contracts must have the same full shard id. Otherwise, such call will fail (TODO: enforce this in VM). This guarantees that both smart contracts will always be in the same shard no matter how the network is resharded.
Calling a smart contract is simliar to Ethereum -- you can either use the UI on the blockchain explorer and load the ABI, or you can use a library like quarkchain-web3.js that handles the interfacing for you. As a note, fromFullShardId
and toFullShardId
must map to the same shard in order for the call to succeed. Otherwise gas will be consumed but the contract will not be called.
Official Website: https://www.quarkchain.io/
Discord Developer Community: https://discord.me/quarkchain