Giter Site home page Giter Site logo

omahs / solang Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hyperledger/solang

0.0 0.0 0.0 14.49 MB

Solidity Compiler for Solana and Substrate

Home Page: https://solang.readthedocs.io/en/latest/

License: Apache License 2.0

C++ 0.01% C 1.83% Rust 85.30% TypeScript 3.93% Makefile 0.01% Dockerfile 0.01% Solidity 8.91%

solang's Introduction

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 example

After installing the compiler, write the following to flipper.sol:

contract flipper {
	bool private value;

	constructor(bool initvalue) public {
		value = initvalue;
	}

	function flip() public {
		value = !value;
	}

	function get() public view returns (bool) {
		return value;
	}
}

Build for Solana

Run:

solang compile --target 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:

solang compile --target 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

Milestone Status
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 Not started
Tooling for calls between ink! <> solidity Not started
Support chain extensions for Substrate Not started
Provide CLI for node interactions Not started

V0.4

Milestone Status
Improve management over optimization passes Not started
Specify values as "1 sol" and "1e9 lamports" In progress
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

solang's People

Contributors

seanyoung avatar lucasste avatar xermicus avatar shekhirin avatar mattsse avatar ryjones avatar kichjang avatar salaheldinsoliman avatar jpopesculian avatar thanhtoantnt avatar rkrasiuk avatar atul9 avatar ctjlewis avatar ethnical avatar ebkalderon avatar guanqun avatar mul53 avatar knarfytrebil avatar extraymond avatar janus avatar taquangtrung avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.