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]
Known Issues
- 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.
using
/for
this
super
selfdestruct(address payable recipient)
<event>.selector
<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})
if
/else
while
do
/while
for
break
continue
return
try
/catch
new
wei
gwei
ether
seconds
minutes
hours
days
weeks
blockhash(uint blockNumber) returns (bytes32)
blobhash(uint index) returns (bytes32)
block.basefee
block.blobbasefee
block.chainid
block.coinbase
block.difficulty
block.gaslimit
block.number
block.prevrandao
block.timestamp
gasleft() returns (uint256)
msg.data
msg.sender
msg.sig
msg.value
tx.gasprice
tx.origin
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)
bytes
bytes.concat(...) returns (bytes memory)
string
string.concat(...) returns (string memory)
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)
ripemd160(bytes memory) returns (bytes20)
ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)
<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)
<address>.delegatecall(bytes memory) returns (bool, bytes memory)
<address>.staticcall(bytes memory) returns (bool, bytes memory)
type(C).name
type(C).creationCode
type(C).runtimeCode
type(I).interfaceId
type(T).min
type(T).max
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...