@0xobelisk/sov-client
TypeScript icon, indicating that this package has built-in type declarations

0.2.8 • Public • Published

@0xobelisk/sov-client

This is an early experimental client used to communicate with the sequencer

Install (TODO: Need release to npmjs)

pnpm i @0xobelisk/sov-client

How to use

Account

import {Ed25519Keypair, getFullnodeUrl, SovereignClient} from "@0xobelisk/sov-client"

const main = async () => {
	// import an Ed25519 account
	const test_private_key: Uint8Array = new Uint8Array([
		117, 251, 248, 217, 135, 70, 194, 105, 46, 80, 41, 66, 185, 56, 200, 35,
		121, 253, 9, 234, 159, 91, 96, 212, 211, 158, 135, 225, 180, 36, 104,
		253,
	]);
	const importKeypair = Ed25519Keypair.fromSecretKey(test_private_key, {
		skipValidation: true,
	});
  
	// generate a new Ed25519 account
	const keypair = new Ed25519Keypair();

	console.log(keypair.getPublicKey());
	console.log(keypair.getSecretKey());
	console.log(keypair.toAddress());

	console.log();

	// generate a new Secp256k1 account
	const ethKey = new Secp256k1Keypair();
	console.log(ethKey.getPublicKey());
	console.log(ethKey.getSecretKey());
};

main();

Submit Transaction

dev in localnet tips: don't forget start the local sov node.

import { Ed25519Keypair, Secp256k1Keypair, SovereignClient, getFullnodeUrl } from '@0xobelisk/sov-client';

const main = async () => {
  const nodeApi = getFullnodeUrl('localnet');
  const client = new SovereignClient(nodeApi);

	// call bank.Freeze func
  	const callPayload: any = {
		bank: {
			Freeze: {
				token_id:
					'token_1rwrh8gn2py0dl4vv65twgctmlwck6esm2as9dftumcw89kqqn3nqrduss6',
			},
		},
	};

	// sign and submit tx
  	await client.signAndExecuteTransaction({
		callPayload,
		signer: keypair
	})
};

main();

Call RPC

dev in localnet tips: don't forget start the local sov node.

import { Ed25519Keypair, Secp256k1Keypair, SovereignClient, getFullnodeUrl } from '@0xobelisk/sov-client';

const main = async () => {
  const nodeApi = getFullnodeUrl('localnet');
  const client = new SovereignClient(nodeApi);

	const params = {
    	user_address:
    		'sov15vspj48hpttzyvxu8kzq5klhvaczcpyxn6z6k0hwpwtzs4a6wkvqwr57gc',
    	token_id:
    		'token_1zdwj8thgev2u3yyrrlekmvtsz4av4tp3m7dm5mx5peejnesga27ss0lusz',
    };
    const balance = await client.query('bank_balanceOf', params);
    console.log(balance);
};

main();

Query Module State

dev in localnet tips: don't forget start the local sov node.

import { Ed25519Keypair, Secp256k1Keypair, SovereignClient, getFullnodeUrl } from '@0xobelisk/sov-client';

const main = async () => {
  const nodeApi = getFullnodeUrl('localnet');
  const client = new SovereignClient(nodeApi);


	const state = await client.get('/xxxx', []);
    console.log(state);
};

main();

How to build sov-client

Clone sov-clone repo

git clone https://github.com/Sovereign-Labs/sov-client

cd sov-client

compile sov-client

pnpm i
ts-node scripts/index.ts

Readme

Keywords

none

Package Sidebar

Install

npm i @0xobelisk/sov-client

Weekly Downloads

36

Version

0.2.8

License

Apache-2.0

Unpacked Size

489 kB

Total Files

100

Last publish

Collaborators

  • vladilenaksana
  • web3henry