Coder Social home page Coder Social logo

multichain-dapp's Introduction

Soroban Multichain Dapp

scaled50_1

Multichain Demo 2

How does it works?

From @soroban-react v5.0.3 (currently supporting preview 9) you can set several networks for your dapp to be contected to.

Just import those networks when creating your Soroban React Provider using

import {futurenet, sandbox, standalone} from '@soroban-react/chains';
import {ChainMetadata} from "@soroban-react/types";
const chains: ChainMetadata[] = [sandbox, standalone, futurenet];

Then, use this chains object to create your Soroban Provider. In this repo example, this is done in src/MySorobanRectProvider.tsx

import React from 'react'
import {SorobanReactProvider} from '@soroban-react/core';
import {futurenet, sandbox, standalone} from '@soroban-react/chains';
import {freighter} from '@soroban-react/freighter';
import {ChainMetadata, Connector} from "@soroban-react/types";
      
const chains: ChainMetadata[] = [sandbox, standalone, futurenet];
const connectors: Connector[] = [freighter()]
                          
                          
  export default function MySorobanReactProvider({children}:{children: React.ReactNode}) {
    return (
      <SorobanReactProvider
        chains={chains}
        appName={"Example Stellar App"}
        connectors={connectors}>
          {children}
      </SorobanReactProvider>
    )
  }

How to test this repo?

1.- Clone & install:

https://github.com/esteblock/multichain-dapp/
cd multichain-dapp
yarn

2.- Initialize a Standalone and a Futurenet blockchain instance in your machine.

In order to test this multichain dapp we are going to use the Standalone and the Futurenet. You are going to initialize both of them using the stellar/quickstart Docker image.

In one terminal do:

bash quickstart.sh standalone

This will open a standalone network in http://localhost:8000

In another terminal do:

bash quickstart.sh futurenet

This will open a futurenet rpc in http://localhost:8001

This, apart of creating a Standalone and Futurenet instance in your machine, it will also create a soroban-preview-9 container using the esteblock/soroban-preview:9 image, that will help you to compile the test smart contract available in ./contract

All of 3 docker containers will be running in a common soroban-network docker network.

3.- Run a bash terminal of soroban-preview-9 Just with

bash run.sh

4.- Compile the Title Smart contract and deploy it in both chains: Inside the soroban-preview-9 container, run

bash initialize.sh

This will compile the smart contract and deploy them both in Standalone and Futurenet. You should see some output like:

Using ARGS: --network standalone --source title-admin
--
--
Deploy the title contract
Contract deployed in standalone network succesfully with ID: e0019c10d10747ce41e3c082b7781915933ce22f3b6cd4b319dfe14477cd45b3
--
--
Setting the first title: My standalone title

--
--
Reading the  read_title function value
"I love Standalone"
.....
.....
Using ARGS: --network futurenet --source title-admin
--
--
Deploy the title contract
Contract deployed in futurenet network succesfully with ID: a1a91a0de70332af2ebb427177663576e42ca364be10d9a4126dcd7b1d951127
--
--
Setting the first title: My futurenet title

--
--
Reading the  read_title function value
"I prefer Futurenet"

Finally it will create a src/contract_ids.json that should look like this:

{
  "standalone": {
    "title_id": "e0019c10d10747ce41e3c082b7781915933ce22f3b6cd4b319dfe14477cd45b3"
  },
  "futurenet": {
    "title_id": "a1a91a0de70332af2ebb427177663576e42ca364be10d9a4126dcd7b1d951127"
  }
}

5.- Configure your Freighter wallet with your Standalone and Futurenet setup. Remember that your local futurenet node is running at http://localhost:8001

Configure your Standalone network in Freighter

Name Standalone
URL http://localhost:8000/soroban/rpc
Passphrase Standalone Network ; February 2017

Configure your Local Futurenet network in Freighter

Name Futurenet Local RPC
URL http://localhost:8001/soroban/rpc
Passphrase Test SDF Future Network ; October 2022

6.- Fund your account using the friendbot For the standalone network is just as easy as typing in your browser:

http://localhost:8000/friendbot?addr=YOUR_PUBLIC_KEY

To use the Futurenet friendbot, visit https://laboratory.stellar.org/#account-creator?network=futurenet

7.- Run the App

yarn dev

Sometimes the dapp does not have permissions to read src/contract_ids.json. If you have that problem, just do, from inside the soroban-preview container:

chmod 777 src/contract_ids.json

multichain-dapp's People

Contributors

esteblock avatar chopan123 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.