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

Lucas Steuernagel cefc34568d Create PDA hash table example (#1438) 2 anos atrás
.github 50aafe94a0 Polkadot: `AssertFailure` emits revert instead trap (#1415) 2 anos atrás
docs cefc34568d Create PDA hash table example (#1438) 2 anos atrás
examples de921953ee add contract author and version flags (#1392) 2 anos atrás
integration cefc34568d Create PDA hash table example (#1438) 2 anos atrás
solana-library 071bdf3fb3 Use anchor npm library rather than @solana/solidity (#1125) 2 anos atrás
solang-parser 9eba67a0f2 Bump crate dependencies (#1417) 2 anos atrás
src 9a53ecbb32 Do not return arguments of revert (#1427) 2 anos atrás
stdlib 2d35ce39da Avoid narrowing casts from size_t to uint32_t (#1426) 2 anos atrás
testdata 6d1d1f715a Update Address and Hash types to ink ABI v4 (#1363) 2 anos atrás
tests 9a53ecbb32 Do not return arguments of revert (#1427) 2 anos atrás
vscode c9e7abfb38 Rename Substrate to Polkadot (#1414) 2 anos atrás
.dockerignore 3d9a197990 Rename scripts to build 4 anos atrás
.gitignore dd5b165617 Remove unwanted files (#1431) 2 anos atrás
.gitmodules c9e7abfb38 Rename Substrate to Polkadot (#1414) 2 anos atrás
.readthedocs.yaml b961ce1d26 Unbreak readthedocs build (#1304) 2 anos atrás
CHANGELOG.md 002954d1d6 v0.3.1: Göttingen release (aka June release) (#1404) 2 anos atrás
CODEOWNERS c9e7abfb38 Rename Substrate to Polkadot (#1414) 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 6efe357e9b Bump solana-rbpf crate to 0.5.0 (#1416) 2 anos atrás
Dockerfile a1913b6953 Bump Solana, Anchor and Ubuntu (#1389) 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 c9e7abfb38 Rename Substrate to Polkadot (#1414) 2 anos atrás
RELEASE_CHECKLIST.md 002954d1d6 v0.3.1: Göttingen release (aka June release) (#1404) 2 anos atrás
SECURITY.md 1ab0e6d503 Correct Hyperledger Defect Response link 4 anos atrás
build.rs 200560e189 Enable tests for stdlib (#1299) 2 anos atrás
clippy.toml bd48744e1f Reduce arguments passed around in sema by using ExprContext 3 anos atrás

README.md

Solang Logo

solang - Solidity Compiler for Solana and Polkadot

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 Polkadot Parachains with the contracts pallet. 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 Polkadot

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

solang compile --target polkadot examples/polkadot/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 polkadot /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 Polkadot target In progress
Provide Solidity -> Polkadot 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