Charcoal is a Solidity-to-Sway translator written in Rust. This tool aims to translate contracts written in Solidity into Sway source code.
This is primarily an educational tool, and some generated Sway code may be incorrect or not optimal.
Please feel free to file an issue.
Compiling the charcoal
binary requires the Rust compiler and its package manager, cargo.
See the Rust Install page for installation options.
cargo run --release -- [OPTIONS]
Flags | |
---|---|
-h , --help |
Prints help information |
-V , --version |
Prints version information |
Options | |
---|---|
-d , --definition-name <definition-name> |
The name of the specific definition to translate. (Optional; Leave unused for all) |
-o , --output-directory <output-directory> |
The path to save the translated Forc project to. (Optional; Must be a directory) |
-t , --target <target> |
The Solidity target file or folder to translate. |
Warning
- Functions that return owned strings may return string constants.
- Contracts that contain inheritance may generate incorrect function implementations.
- Structures that contain mappings may not be translated correctly.
- Pointer types may not be translated correctly.
- Signed integers support is incomplete.
- Low level calls are not all supported.
- Contract creation with
new
is not supported.
- Language Items
- Import Directives
- Struct Types
- Enum Types
- Interfaces
- Libraries
-
using
/for
- Contract-related
-
this
-
super
-
(NOTE: Unsupported)selfdestruct(address payable recipient)
-
- State Variables
- Constant
- Immutable
- Regular
- Functions
- Parameters
- Return Variables
- Returning Multiple Values
- View Functions
- Pure Functions
-
Receive Ether Function(NOTE: Unsupported) -
Fallback Function(NOTE: Unsupported) - Function Overloading
- Function Modifiers
-
Function Signatures(NOTE: Unsupported) -
Function Selectors(NOTE: Unsupported)
- Inheritance
- Inheritance Specification
- Function Overriding
- Modifier Overriding
- Constructors
- Events
- Event Type Declarations
-
Indexed Parameters(NOTE: Unsupported) -
(NOTE: Unsupported)<event>.selector
- Error Handling
- Error Type Declarations
-
(NOTE: Unsupported)<error>.selector
-
assert(bool condition)
-
require(bool condition)
-
require(bool condition, string memory message)
-
revert()
-
revert(string memory reason)
-
revert Error(1, 2, 3)
-
revert Error({a: 1, b: 2, c: 3})
- Control Structures
-
if
/else
-
while
-
do
/while
-
for
-
break
-
continue
-
return
-
try
/catch
-
- Function Calls
- Internal Function Calls
- External Function Calls
- Function Calls with Named Parameters
- Omitted Names in Function Definitions
- Creating Contracts via
new
- Ether Units
-
wei
-
gwei
-
ether
-
- Time Units
-
seconds
-
minutes
-
hours
-
days
-
weeks
-
- Block and Transaction Properties
-
blockhash(uint blockNumber) returns (bytes32)
-
(NOTE: Unsupported)blobhash(uint index) returns (bytes32)
-
(NOTE: Unsupported)block.basefee
-
(NOTE: Unsupported)block.blobbasefee
-
block.chainid
-
block.coinbase
-
(NOTE: Unsupported)block.difficulty
-
block.gaslimit
-
block.number
-
(NOTE: Unsupported)block.prevrandao
-
block.timestamp
-
gasleft() returns (uint256)
-
msg.data
-
msg.sender
-
(NOTE: Unsupported)msg.sig
-
msg.value
-
tx.gasprice
-
(NOTE: Unsupported)tx.origin
-
- ABI Encoding and Decoding Functions
-
abi.decode(bytes memory encodedData, (...)) returns (...)
-
abi.encode(...) returns (bytes memory)
-
abi.encodePacked(...) returns (bytes memory)
-
abi.encodeWithSelector(bytes4 selector, ...) returns (bytes memory)
-
abi.encodeWithSignature(string memory signature, ...) returns (bytes memory)
-
abi.encodeCall(function functionPointer, (...)) returns (bytes memory)
-
- Members of
bytes
-
bytes.concat(...) returns (bytes memory)
-
- Members of
string
-
string.concat(...) returns (string memory)
-
- Mathematical and Cryptographic Functions
-
addmod(uint x, uint y, uint k) returns (uint)
-
mulmod(uint x, uint y, uint k) returns (uint)
-
keccak256(bytes memory) returns (bytes32)
-
sha256(bytes memory) returns (bytes32)
-
(NOTE: Unsupported)ripemd160(bytes memory) returns (bytes20)
-
ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)
-
- Members of Address Types
-
<address>.balance (uint256)
-
<address>.code (bytes memory)
-
<address>.codehash (bytes32)
-
<address payable>.transfer(uint256 amount)
-
<address payable>.send(uint256 amount) returns (bool)
-
<address>.call(bytes memory) returns (bool, bytes memory)
-
(NOTE: Unsupported)<address>.delegatecall(bytes memory) returns (bool, bytes memory)
-
(NOTE: Unsupported)<address>.staticcall(bytes memory) returns (bool, bytes memory)
-
- Type Information
-
type(C).name
-
type(C).creationCode
-
type(C).runtimeCode
-
type(I).interfaceId
-
type(T).min
-
type(T).max
-
- Inline Assembly Statements
- Assignments
- Variable Declarations
- If Statements
- For Statements
- Switch Statements
- Leave Statements
- Break Statements
- Continue Statements
- Block Statements
- Function Definitions
- Function Calls
- Inline Assembly Expressions
- Boolean Literals
- Number Literals
- Hex Number Literals
- Hex String Literals
- String Literals
- Variable Identifiers
- Function Calls
- Suffix Access
- Inline Assembly Built-In Functions
-
stop
-
add
-
mul
-
sub
-
div
-
sdiv
-
mod
-
smod
-
exp
-
not
-
lt
-
gt
-
slt
-
sgt
-
eq
-
iszero
-
and
-
or
-
xor
-
byte
-
shl
-
shr
-
sar
-
addmod
-
mulmod
-
signextend
-
sha3
-
keccak256
-
pc
-
pop
-
mload
-
mstore
-
mstore8
-
sload
-
sstore
-
tload
-
tstore
-
msize
-
gas
-
address
-
balance
-
selfbalance
-
caller
-
callvalue
-
calldataload
-
calldatasize
-
calldatacopy
-
codesize
-
codecopy
-
extcodesize
-
extcodecopy
-
returndatasize
-
returndatacopy
-
mcopy
-
extcodehash
-
create
-
create2
-
call
-
callcode
-
delegatecall
-
staticcall
-
return
-
revert
-
selfdestruct
-
invalid
-
log0
-
log1
-
log2
-
log3
-
log4
-
chainid
-
basefee
-
blobbasefee
-
origin
-
gasprice
-
blockhash
-
blobhash
-
coinbase
-
timestamp
-
number
-
difficulty
-
prevrandao
-
gaslimit
-
datasize
-
dataoffset
-
datacopy
-
setimmutable
-
loadimmutable
-
linkersymbol
-
memoryguard
-
verbatim...
-