Skip to content

Pzixel/Solidity.Roslyn

Repository files navigation

Solidity.Roslyn

CircleCI

This library allows you to generate C# wrapper over Solidity contracts, targeting netstandard library. It requires solc available in PATH when building. You can install it for your OS (see instruction) or use prebuilt docker image.

image

Sample usage

  1. Create a new netstandard project and add solidity file with code
contract SampleContract {
    uint64 public x;
    uint64 public y;

    constructor(uint64 x_, uint64 y_) public {
        x = x_;
        y = y_;
    }
}
  1. Reference Solidity.Roslyn, Solidity.Roslyn.Core and required build packages
Install-Package Solidity.Roslyn
Install-Package Solidity.Roslyn.Core
Install-Package CodeGeneration.Roslyn.BuildTime -Version 0.4.88
  1. Add codegen attribute in the project
using Solidity.Roslyn;

[assembly: Solidity]
  1. Build the project and start calling the contract!:
const ulong X = 10;
const ulong Y = 20;
var sample = await SampleContract.DeployAsync(Web3, X, Y);
ulong x = await sample.XAsync();
ulong y = await sample.YAsync();

Assert.Equal(X, x);
Assert.Equal(Y, y);

For more details see Example project

Also you may find Solidity code highlighter useful.

This playground was used to run integrational tests. If you have different connection settings put them in EthereumSettings class in Solidity.Roslyn.Test.Integrational project.

About

Library that allows you to automatically generate C# wrappers over Solidity contracts

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages