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

Sean Young a1913b6953 Bump Solana, Anchor and Ubuntu (#1389) 2 жил өмнө
.github a1913b6953 Bump Solana, Anchor and Ubuntu (#1389) 2 жил өмнө
docs a1913b6953 Bump Solana, Anchor and Ubuntu (#1389) 2 жил өмнө
examples d772fe4bf9 Read compiler configurations from toml (#1347) 2 жил өмнө
integration a1913b6953 Bump Solana, Anchor and Ubuntu (#1389) 2 жил өмнө
solana-library 071bdf3fb3 Use anchor npm library rather than @solana/solidity (#1125) 2 жил өмнө
solang-parser 256b76e2e4 Refactor constructor annotations (#1366) 2 жил өмнө
src d0d65283ba Optimize modifier CFGs (#1391) 2 жил өмнө
stdlib 15d92e9169 Add padding in account deserialization (#1306) 2 жил өмнө
testdata 6d1d1f715a Update Address and Hash types to ink ABI v4 (#1363) 2 жил өмнө
tests d0d65283ba Optimize modifier CFGs (#1391) 2 жил өмнө
vscode 1a47714956 `this` is not a keyword (#1317) 2 жил өмнө
.dockerignore 3d9a197990 Rename scripts to build 4 жил өмнө
.gitignore 01707781ad Substrate: `subxt` integration tests (#990) 2 жил өмнө
.gitmodules c98dfd3fa7 Tornado cash on Substrate :rocket: (#1360) 2 жил өмнө
.readthedocs.yaml b961ce1d26 Unbreak readthedocs build (#1304) 2 жил өмнө
CHANGELOG.md 53172f3ad3 v0.3.0 Venice (#1319) 2 жил өмнө
CODEOWNERS cf83e286b5 Followup regarding subxt test (#1381) 2 жил өмнө
CODE_OF_CONDUCT.md 3d8f6ba7af Add standard repo files 5 жил өмнө
CONTRIBUTING.md 3d8f6ba7af Add standard repo files 5 жил өмнө
Cargo.toml d772fe4bf9 Read compiler configurations from toml (#1347) 2 жил өмнө
Dockerfile a1913b6953 Bump Solana, Anchor and Ubuntu (#1389) 2 жил өмнө
LICENSE 9d35806f37 Update license file to reflect that Solang is Apache-2.0 only 4 жил өмнө
MAINTAINERS.md 0cfb7f3de2 Add Cyrill to maintainers list (#917) 3 жил өмнө
README.md a1913b6953 Bump Solana, Anchor and Ubuntu (#1389) 2 жил өмнө
RELEASE_CHECKLIST.md 702be7c877 dev weekly seems gone and update solana installer (#1322) 2 жил өмнө
SECURITY.md 1ab0e6d503 Correct Hyperledger Defect Response link 4 жил өмнө
build.rs 200560e189 Enable tests for stdlib (#1299) 2 жил өмнө
clippy.toml bd48744e1f Reduce arguments passed around in sema by using ExprContext 3 жил өмнө

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 @coral-xyz/anchor:

npm install @coral-xyz/anchor

Save the following to flipper.js:

const { readFileSync } = require('fs');
const anchor = require('@coral-xyz/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.4

Feature Status
Improve management over optimization passes Not started
Adopt single static assignment for code generation In progress
Support openzeppelin on Substrate target In progress
Provide Solidity -> Substrate porting guide Not started
Call Solidity from Solana's Rust contracts Not started
Tooling for calls between ink! <> solidity In progress
Provide CLI for node interactions In progress

License

Apache 2.0