Web3
DAPPs
Introduction

Introduction

Now let's integrate blockchain and smart contracts into one website. For this we use the library @bywise/provider (opens in a new tab) and @bywise/web3 (opens in a new tab)

Let's use this NextJS project as an example:

First we create a new instance of the provider. We pass the network to which it will connect as a parameter.

const chain = 'mainnet'
const provider = new BywiseProvider(chain);

We created the Try Connect button that tries to connect with the user's wallet. After that, we fetch some information from the connected address.

const connect = async () => {
    const userInfo = await provider.connect();
 
    if (userInfo) {
        console.log('userInfo', userInfo)
        setAddress(provider.address)
 
        const infoBlockchainUser = await provider.web3.wallets.getWalletInfo(provider.address, chain);
        console.log('infoBlockchainUser', infoBlockchainUser)
        if (infoBlockchainUser) {
            setBalance(infoBlockchainUser.balance)
            setName(infoBlockchainUser.name)
        }
        setConnect(true);
    }
}

Now that we are connected, we can try to perform a simple transaction.

const trySendTransaction = async () => {
    const result = await provider.send({
        to: [BywiseHelper.ZERO_ADDRESS],
        amount: ['0'],
        type: TxType.TX_JSON,
        data: {
            myData: `huehuehue`
        }
    });
    if (result) {
        console.log('result', result)
        alert(`success - txId: ${result.tx.hash}`);
    } else {
        alert(`canceled transaction`);
    }
}