Mirroring https://github.com/hyperledger-solang/solang

Sean Young a47fe3f101 v0.2.3 Geneva (#1256) 2 anos atrás
.github c5afda5f64 chore(ci): update github actions 2 anos atrás
docs a47fe3f101 v0.2.3 Geneva (#1256) 2 anos atrás
examples 91da9f3ae3 Fix flipper.sol example (#1206) 2 anos atrás
integration 1ba694bc16 Remove overflow flag 2 anos atrás
solana-library 071bdf3fb3 Use anchor npm library rather than @solana/solidity (#1125) 2 anos atrás
solang-parser a47fe3f101 v0.2.3 Geneva (#1256) 2 anos atrás
src 3b03af14d2 explicitly disallow rational comparisons (#1221) 2 anos atrás
stdlib d72d82c9d6 Refactor substrate dispatcher into codegen (#1249) 2 anos atrás
tests 3b03af14d2 explicitly disallow rational comparisons (#1221) 2 anos atrás
vscode 53177f6d94 error should not be a keyword (#1196) 2 anos atrás
.dockerignore 3d9a197990 Rename scripts to build 4 anos atrás
.gitignore 0344a87cf8 Feature ink metadata for substrate (#989) 3 anos atrás
.gitmodules f2bbcbd954 test(parser): semantic & syntax tests from ethereum/solidity (#787) 3 anos atrás
CHANGELOG.md a47fe3f101 v0.2.3 Geneva (#1256) 2 anos atrás
CODEOWNERS 43cdc7ee15 Expand list of code owners, take #2 (#1176) 2 anos atrás
CODE_OF_CONDUCT.md 3d8f6ba7af Add standard repo files 5 anos atrás
CONTRIBUTING.md 3d8f6ba7af Add standard repo files 5 anos atrás
Cargo.toml a47fe3f101 v0.2.3 Geneva (#1256) 2 anos atrás
Dockerfile 64f72b4993 Bump MSRV to 1.65 (#1236) 2 anos atrás
LICENSE 9d35806f37 Update license file to reflect that Solang is Apache-2.0 only 4 anos atrás
MAINTAINERS.md 0cfb7f3de2 Add Cyrill to maintainers list (#917) 3 anos atrás
README.md a47fe3f101 v0.2.3 Geneva (#1256) 2 anos atrás
RELEASE_CHECKLIST.md c4447079d7 Release v0.2.1 (#1120) 2 anos atrás
SECURITY.md 1ab0e6d503 Correct Hyperledger Defect Response link 4 anos atrás
build.rs 743d898669 Fixes for rust 1.67 clippy (#1136) 2 anos atrás
clippy.toml bd48744e1f Reduce arguments passed around in sema by using ExprContext 3 anos atrás
requirements.txt 39418e9427 allow newer docutils (#1118) 2 anos atrás

README.md

Solang Logo

solang - Solidity Compiler for Solana and Substrate

Discord CI Documentation Status license LoC

Welcome to Solang, a new Solidity compiler written in rust which uses llvm as the compiler backend. Solang can compile Solidity for Solana and Substrate. Solang is source compatible with Solidity 0.8, with some caveats due to differences in the underlying blockchain.

Solang is under active development right now, and has extensive documentation.

Installation

Solang is available as a Brew cask for MacOS, with the following command:

brew install hyperledger/solang/solang

For other operating systems, please check the installation guide.

Simple examples

Build for Solana

Run the following command, selecting the flipper example available in Solang's repository:

solang compile --target solana examples/solana/flipper.sol

Alternatively if you want to use the solang container, run:

docker run --rm -it -v $(pwd):/sources ghcr.io/hyperledger/solang compile -v -o /sources --target solana /sources/solana/flipper.sol

This generates a file called flipper.json and flipper.so. In order to deploy the contract code to the account F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC, save the private key to the file flipper-keypair.json:

echo "[4,10,246,143,43,1,234,17,159,249,41,16,230,9,198,162,107,221,233,124,34,15,16,57,205,53,237,217,149,17,229,195,3,150,242,90,91,222,117,26,196,224,214,105,82,62,237,137,92,67,213,23,14,206,230,155,43,36,85,254,247,11,226,145]" > flipper-keypair.json

Now you can deploy the contract code using:

solana program deploy flipper.so

Now install @project-serum/anchor:

npm install @project-serum/anchor

Save the following to flipper.js:

const { readFileSync } = require('fs');
const anchor = require('@project-serum/anchor');

const IDL = JSON.parse(readFileSync('./flipper.json', 'utf8'));
const PROGRAM_SO = readFileSync('./flipper.so');

(async function () {
	const provider = anchor.AnchorProvider.env();

	const dataAccount = anchor.web3.Keypair.generate();

	const programId = new anchor.web3.PublicKey(IDL.metadata.address);

	const wallet = provider.wallet.publicKey;

	const program = new anchor.Program(IDL, programId, provider);

	await program.methods.new(wallet, true)
		.accounts({ dataAccount: dataAccount.publicKey })
		.signers([dataAccount]).rpc();

	const val1 = await program.methods.get()
		.accounts({ dataAccount: dataAccount.publicKey })
		.view();

	console.log(`state: ${val1}`);

	await program.methods.flip()
		.accounts({ dataAccount: dataAccount.publicKey })
		.rpc();

	const val2 = await program.methods.get()
		.accounts({ dataAccount: dataAccount.publicKey })
		.view();

	console.log(`state: ${val2}`);
})();

And now run:

export ANCHOR_WALLET=$HOME/.config/solana/id.json
export ANCHOR_PROVIDER_URL=http://127.0.0.1:8899
node flipper.js

Build for Substrate

Run the following command, selecting the flipper example available on Solang's repository:

solang compile --target substrate examples/substrate/flipper.sol

Alternatively if you want to use the solang container, run:

docker run --rm -it -v $(pwd):/sources ghcr.io/hyperledger/solang compile -v -o /sources --target substrate /sources/flipper.sol

You will have a file called flipper.contract. You can use this directly in the Contracts UI, as if your smart contract was written using ink!.

Tentative roadmap

Solang has a high level of compatibility with many blockchains. We are trying to ensure the compiler stays up to date with the newest Solidity syntax and features. In addition, we focus on bringing new performance optimizations and improve developer experience. Here is a brief description of what we envision for the next versions.

V0.3

Feature Status
Specify values as "1 sol" and "1e9 lamports" Completed
Call Solana's Rust contracts from Solidity Completed
Improvements in overflow checking Completed
Support Solana's Program Derived Addresses Completed
Call Solidity from Solana's Rust contracts Not started
Improve developer experience for Substrate Complete
Tooling for calls between ink! <> solidity In progress
Support chain extensions for Substrate Not started
Provide CLI for node interactions Not started

V0.4

Feature Status
Improve management over optimization passes Not started
Adopt single static assignment for code generation Not started
Support openzeppelin on Substrate target Not started
Provide Solidity -> Substrate porting guide Not started

License

Apache 2.0