Git Product home page Git Product logo

filecoindot's Introduction

filecoindot

github build status license

A Substrate pallet to bridge from Filecoin to any blockchain built using the Substrate framework, including Polkadot parachains.

How to integrate the Filecoin bridge pallet into a runtime?

0. configure filecoindot into your node

Here we need to configure filecoindot into our runtime first, see substrate-node-example for detail.

1. set signer account to your node

Generate an account with subkey for our offchain worker first

$ subkey generate
Secret phrase `brief outside human axis reveal boat warm amateur dish sample enroll moment` is account:
  Secret seed:      0x4ebb14295f95e62a865a457629a8e6d96ef5f3cf1896a9624d2e91e09f4cdc65
  Public key (hex): 0x0676a4b19c66b31e12d15fe31ccbc775d3d2cda6e1c8686e395118f808eaa118
  Account ID:       0x0676a4b19c66b31e12d15fe31ccbc775d3d2cda6e1c8686e395118f808eaa118
  SS58 Address:     5CDBPWWtnLTqSUSNvB5BGYMs23Vs8dDHwWpjWpebBRErZM9W

and then, post your account to the node

$ curl -X POST -vk 'http://localhost:9933' -H "Content-Type:application/json;charset=utf-8" \
  -d '{
    "jsonrpc":2.0,
    "id":1,
    "method":"author_insertKey",
    "params": [
      "fdot",
      "0x4ebb14295f95e62a865a457629a8e6d96ef5f3cf1896a9624d2e91e09f4cdc65",
      "0x0676a4b19c66b31e12d15fe31ccbc775d3d2cda6e1c8686e395118f808eaa118"
    ]
  }'

2. set filecoin rpc endpoint to your node

curl -X POST -H "Content-type: application/json"  http://localhost:9933 -d '
{
  "method": "filecoindot_setRpcEndpoint",
  "jsonrpc": "2.0",
  "id": 0,
  "params": ["http://user:[email protected]"]
}
'

If you can see the logs below in your terminal

2021-10-31 21:58:55 Running in --dev mode, RPC CORS has been disabled.
2021-10-31 21:58:55 Substrate Node
2021-10-31 21:58:55 ✌️  version 3.0.0-9e5d007-aarch64-macos
2021-10-31 21:58:55 ❤️  by Substrate DevHub <https://github.com/substrate-developer-hub>, 2017-2021
2021-10-31 21:58:55 📋 Chain specification: Development
2021-10-31 21:58:55 🏷 Node name: fuzzy-doctor-8068
2021-10-31 21:58:55 👤 Role: AUTHORITY
2021-10-31 21:58:55 💾 Database: RocksDb at /Users/clearloop/Library/Application Support/node-template/chains/dev/db
2021-10-31 21:58:55 ⛓  Native runtime: node-template-100 (node-template-1.tx1.au1)
2021-10-31 21:58:55 Using default protocol ID "sup" because none is configured in the chain specs
2021-10-31 21:58:55 🏷 Local node identity is: 12D3KooWPY6sbvMAryQkXRDKiApkd75Ak8x7cbgEqtiEzFxb5kQF
2021-10-31 21:58:55 could not parse an IP from hosts file
2021-10-31 21:58:57 📦 Highest known block at #168
2021-10-31 21:58:57 〽️ Prometheus exporter started at 127.0.0.1:9615
2021-10-31 21:58:57 Listening for new connections on 127.0.0.1:9944.
2021-10-31 21:59:00 🙌 Starting consensus session on top of parent 0x6b98f8856f41abfb45da878188aaff1419c1cb6bbb8a56a346e9f1f39613a1a4
2021-10-31 21:59:00 🎁 Prepared block for proposing at 169 [hash: 0x9f3941c44fdacc7f240b0471c97cd61e5010377619501285999ab0ff4d0edbbc; parent_hash: 0x6b98…a1a4; extrinsics (1): [0x1dd1…1b8b]]
2021-10-31 21:59:00 🔖 Pre-sealed block for proposal at 169. Hash now 0x53480ec65b6b2c13126a96c62089af0244a570ba961efdd0d377a44df12a5a5b, previously 0x9f3941c44fdacc7f240b0471c97cd61e5010377619501285999ab0ff4d0edbbc.
2021-10-31 21:59:00 ✨ Imported #169 (0x5348…5a5b)
2021-10-31 21:59:00 bootstrap filecoindot ocw with filecoin rpc endpoint http://user:[email protected]

the filecoindot offchain worker has been set up!

3. set the the offchain worker's account as relayer

In the provided substrate-node-example, we configured the type ManagerOrigin of filecoindot with frame_system::EnsureRoot<AccountId>, so here we need to add_relayer with sudo access.

For setting relayer in polkadot.js.org/apps, we need to click Developer -> Sudo -> filecoindot -> add_relayer and choose an account to be the new relayer.

Or with @polkadot/api, you can use the code below:

import { ApiPromise, WsProvider } from "@polkadot/api";
import { rpc, types } from "@filecoindot/types";
import { Keyring } from "@polkadot/keyring";

(async () => {
    // setup api
    const provider = new WsProvider("http://0.0.0.0:9944");
    const api = await ApiPromise.create({ provider, types, rpc });
    
    // setup singer
    const keyring = new Keyring({ type: "sr25519" });
    const signer = keyring.addFromUri("//Alice");
    
    // execute the `add_relayer` extrinsic
    const tx_hash = await api.tx.sudo
      .sudo(this._.tx.filecoindot.addRelayer(signer.address))
      .signAndSend(signer);
})();

4. Full Example

See the example runtime for a full example showing how to integrate the pallet into a substrate runtime.

ChainSafe Security Policy

Reporting a Security Bug

We take all security issues seriously, if you believe you have found a security issue within a ChainSafe project please notify us immediately. If an issue is confirmed, we will take all necessary precautions to ensure a statement and patch release is made in a timely manner.

Please email us a description of the flaw and any related information (e.g. reproduction steps, version) to security at chainsafe dot io.

filecoindot's People

Contributors

clearloop avatar mattsse avatar dependabot[bot] avatar willeslau avatar ivanceras avatar

Watchers

 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.