Socket
Book a DemoInstallSign in
Socket

soy-core

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

soy-core

Javascript api for soy interactions

1.1.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source



ENS+IPFS ❤ DevOps - Static Websites on the Distributed Web

UsagePackagesAPIContributingLicense

Soy is a collection of smart contracts and tools to enable you to build your site on the distributed web. By virtue of using ENS and IPFS your content will be quickly accessible all over the world without having to set up or manage any infrastructure.

Already have an ENS resolver? Add .soy to the end to see it in your browser! Check out web3studio.eth.soy


Usage

Install

# Yarn
$ yarn add --dev soy-core

# NPM
$ npm install --save-dev soy-core

Configure

Create a new soy instance and give it any Web3 provider.

const Soy = require('soy-core');
const HDWalletProvider = require('truffle-hdwallet-provider');

const mnemonic = process.env.WALLET_MNEMONIC;
const infuraApiKey = process.env.INFURA_API_KEY;
const infuraNetwork = process.env.INFURA_NETWORK;
const provider = new HDWalletProvider(
  mnemonic,
  `https://${infuraNetwork}.infura.io/v3/${infuraApiKey}`
);

const soy = new Soy(provider);

Scripting

Scripting with Soy usually looks something like this. This is an example of creating a new Soy instance and using it to register a domain and publish the contenthash for the site.

const Soy = require('soy-core');
const Web3 = require('web3');
const HDWalletProvider = require('truffle-hdwallet-provider');

// Change these paremeters or pass them in as env variables
const mnemonic = process.env.WALLET_MNEMONIC;
const infuraApiKey = process.env.INFURA_API_KEY;
const infuraNetwork = process.env.INFURA_NETWORK || 'rinkeby';
const contentHash = '/ipfs/QmVyYoFQ8KDLMUWhzxTn24js9g5BiC6QX3ZswfQ56T7A5T';
const domain = 'soyexample.test';

var provider = new HDWalletProvider(
  mnemonic,
  `https://${infuraNetwork}.infura.io/v3/${infuraApiKey}`
);

(async () => {
  const web3 = new Web3(provider);
  const accounts = await web3.eth.getAccounts();
  const owner = accounts[0];

  const soy = new Soy(provider, { from: owner });

  const resolver = await soy.registerDomain(domain);
  const revision = await resolver.publishRevision(contentHash);

  console.log(`Revision ${revision} published by Soy!`);
})().catch(console.log);

View Your Beautiful Site

Once you have ENS set up to point to an ipfs hash, simply add .soy to the ENS domain in your browser. For example, web3studio.eth becomes web3studio.eth.soy.

Packages

Soy consists of a bunch of tools that make hosting distributed web sites easy. They are:

soy-contracts

Contracts contains the source of the solidity contracts and a low level interface for interactions via truffle-contract.

For more information, see soy-contracts's main page.

soy-gateway

The gateway is the source code behind eth.soy. It's a shim to enable browsers to support distributed file systems over ENS until browsers can handle this natively.

For more information, see soy-gateway's main page.

soy-core

The core project contains a friendly js interface to interacting with the deployed contracts of soy-contracts enabling you to get your content out there with ease.

API

Classes

Ens

Soy's ENS resolver which caches all results per domain's TTL set by it's resolver.

Resolver

A nod specific resolver

Soy

Soy is the best interface for Soy's smart contracts. It provides an easily scriptable interface for any deployment pattern.

Ens

Soy's ENS resolver which caches all results per domain's TTL set by it's resolver.

Kind: global class

new Ens(provider, [registryAddress])

Constructor

ParamTypeDescription
providerObjectA web3@1 provider, defaults to localhost
[registryAddress]stringAn optional registry address for bespoke networks

Example (Get the `contenthash` for a domain)

const siteHash = soy.ens.getContentHash('web3studio.eth');

ens.resolver(domain) ⇒ Promise.<SoyPublicResolver>

Gets a resolver contract instance for a registered ENS domain

Kind: instance method of Ens
Returns: Promise.<SoyPublicResolver> - Resolver for a domain

ParamTypeDescription
domainstringENS domain (eg: web3studio.eth)

ens.getContentHash(domain) ⇒ Promise.<string>

Resolves the contenthash for an ENS domain

Kind: instance method of Ens
Returns: Promise.<string> - The contenthash for the ENS domain

ParamTypeDescription
domainstringENS domain (eg: web3studio.eth)

Resolver

A nod specific resolver

Kind: global class

new Resolver(domain, resolver)

Create a unique contract instance with common params filled in. Wraps all methods of SoyPublicResolver and by extension the base PublicResolver without the need to specify a namehashed domain and tedious unit conversions.

truffle-contract is used to generate the interface. For more detailed explanations, see their docs

ParamTypeDescription
domainstringens domain
resolverSoyPublicResolverA resolver contract

resolver.publishRevision(contentHash, [alias], [txOps]) ⇒ Promise.<number>

Publishes the content hash as a revision

Kind: instance method of Resolver
Returns: Promise.<number> - The revision number

ParamTypeDescription
contentHashstringContent hash to publish for your site
[alias]stringalias to set for this hash
[txOps]Objectweb3 transactions options object

resolver.contenthash() ⇒ Promise.<string>

Get the current contenthash

Kind: instance method of Resolver
Returns: Promise.<string> - current resolver content hash

Soy

Soy is the best interface for Soy's smart contracts. It provides an easily scriptable interface for any deployment pattern.

Kind: global class
Properties

NameTypeDescription
ensENSENS resolver utility
web3Web3web3.js instance
ipfsIPFSipfs-http-client instance

new Soy(provider, [options])

Create a new soy instance

ParamTypeDescription
providerWeb3.ProviderA Web3 provider instance
[options]ObjectSoy instance options
[options.registryAddress]stringAn address for a deployed ENS registry
[options.resolverAddress]stringAn address for a deploy SoyPublicResolver
[...options.txOps]ObjectDefault transaction arguments passed to web3

soy.uploadToIPFSAndPublish(path, domain, [options]) ⇒ Promise.<{hash: string, rev: number}>

Upload the contents of a directory to ipfs and publishes the root folder's hash as a revision

Kind: instance method of Soy
Returns: Promise.<{hash: string, rev: number}> - - The hash published and it's revision number

ParamTypeDescription
pathstringPath to the directory
domainstringENS domain to publish a revision
[options]ObjectIPFS options

soy.resolver(domain) ⇒ Promise.<Resolver>

With a registered domain, get a resolver instance for a specific node

Kind: instance method of Soy
Returns: Promise.<Resolver> - - A resolver instance

ParamTypeDescription
domainstringThe domain for the node

Example (Publish a revision of your site)

const resolver = await soy.resolver('example.madewith.eth');

await resolver.publishRevision(
  '/ipfs/QmVyYoFQ8KDLMUWhzxTn24js9g5BiC6QX3ZswfQ56T7A5T'
);

soy.registerDomain(domain) ⇒ Promise.<Resolver>

Registers a new domain and sets it's resolver to Soy's PublicResolver contract. This will only need to be done once per (sub)domain

If you haven't done so yet, you will need to purchase a domain. We recommend using My Ether Wallet. Domain auctions will last a week.

Kind: instance method of Soy
Returns: Promise.<Resolver> - a resolver instance

ParamTypeDescription
domainstringa new ENS domain to register

Example (Register an ENS Domain with Soy)

const resolver = await soy.registerDomain('example.madewith.eth');

Contributing

Please read through our contributing guidelines. Included are directions for coding standards, and notes on development.

License

Apache 2.0

Keywords

soy

FAQs

Package last updated on 30 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.