Wallet Connector
Sodium is compatible with all standard Ethereum libraries and connectors. If your developed dApp works with MetaMask, it will automatically work with Sodium as well
web3.js
import Web3 from 'web3';
web3 = new Web3();
const provider = wallet.getProvider();
web3.setProvider(provider);
const walletAddress = await web3.eth.getCoinbase();
// sign
web3.eth.sign("Hello world", walletAddress);
// send transaction
web3.eth.sendTransaction({
from: walletAddress,
to: "0x812D3C67d283F3b9d1F1E347DF37F0C7fbD6a0B0",
value: "1000000000000000000"
});
web3-react-v8
import { initializeConnector, Web3ReactHooks } from '@web3-react/core'
import { Connector } from '@web3-react/types'
// https://github.com/sodiumlabs/demo-dapp-web3-react/blob/main/src/connectors/sodium.ts
import { SodiumConnector } from './sodium'
export enum ConnectionType {
SODIUM = 'SODIUM',
}
export interface Connection {
connector: Connector
hooks: Web3ReactHooks
type: ConnectionType
}
// @ts-ignore
const [web3Sodium, web3SodiumHooks] = initializeConnector<SodiumConnector>(
(actions) =>
new SodiumConnector({
actions,
config: {
defaultNetworkId: 80001,
walletAppURL: 'https://sodium-two.vercel.app',
transports: {
iframeTransport: {
enabled: true,
}
},
},
})
)
export const sodiumConnection: Connection = {
connector: web3Sodium,
hooks: web3SodiumHooks,
type: ConnectionType.SODIUM,
}
// connect
sodiumConnection.connector.activate();
// get provider
const provider = sodiumConnection.hooks.useProvider();
// signer
const signer = await provider!.getSigner()
// sign
const sig = await signer.signMessage(message)
console.log('signature:', sig)
Last updated