Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
provider.version;
// trueprovider.version;
// "3.5.2"type ChainId =
| "1" // Constellation MainNet
| "3"; // Ceres Testnet (fka. Exchanges Network)await provider.request({ method: "dag_chainId", params: [] });
// "3"await provider.request({ method: "dag_getBalance" });
// "1000"type ErrorTypes = {
// Base Stargazer Error.
StargazerError;
// Errors thrown by the injected WalletProvider.
StargazerWalletProviderError;
// General errors thrown by a chain provider.
StargazerChainProviderError;
// RPC related requests errors thrown by a chain provider. Complies with EIP-1193.
StargazerChainProviderRpcError;
};window.stargazer.errorTypes;
/* {
StargazerError: ƒ,
StargazerWalletProviderError: ƒ,
StargazerChainProviderError: ƒ,
StargazerChainProviderRpcError: ƒ
} */type TokenLock = {
source: string; // Wallet address signing the transaction
amount: number; // The amount to lock
// Must be in DATUM
currencyId: string | null; // The currency metagraph identifier that the user wants to lock
// For DAG, this field must be null
fee?: number; // The fee in the currency of the currency metragraph, or DAG.
// If not provided, the default fee will be 0
// Must be in DATUM
unlockEpoch: number | null; // The global snapshot epoch progress to unlock the tokens
// If provided, must be greater than the currentEpoch
};await provider.request({
method: "dag_getPublicKey",
params: ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX"],
});
// "0482c4566a9c4cbb6f23b9a31c96876501c71f5c04b35f416e0b2243113cce8fb386a2db0b3881d1c908d33465748b948649165a6705904120238999eed6eed1f4"await provider.request({ method: "dag_accounts", params: [] });
// ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX"]await provider.request({
method: "dag_getMetagraphBalance",
params: ["DAG0KheCYqEmFoQEWdFwrZGaXabJsWJyUvjpsLjE"],
});
// "1000"await provider.request({ method: "eth_blockNumber", params: [] });
// "0xe659e6"
await provider.onAsync("accountsChanged", () => {
// Do something when accounts changed
});type Transaction = {
source: Address // Address of the sender.
destination: Address // Address of the receiver.
amount: Number // DATUM sent with this transaction to the receiver.
fee?: Number // DATUM fee used for the transaction.
}await provider.request({
method: "dag_sendTransaction",
params: [
{
source: "DAG77zerQ2BUVhtVgkmseihkEfLXieBBm57vqA4J",
destination: "DAG2fMnbEmsWhgYGhvdREVELyESKUqGNTEWf4B61",
amount: 100000000, // 100000000 DATUM = 1 DAG
fee: 0,
},
],
});
// "2d9fe9bad17debed7c903f22b74aac8af270daea7995dd099a58d6b201547169"await provider.request({
method: "eth_gasPrice",
params: [],
});
// "0x12a05f200"await provider.request({
method: "eth_protocolVersion",
params: [],
});
// "0x3f"type Transaction = {
metagraphAddress: Address; // Address of the metagraph
source: Address; // Address of the sender.
destination: Address; // Address of the receiver.
amount: Number; // Amount sent with this transaction to the receiver. (8 decimals)
fee?: Number; // Fee used for the transaction. (8 decimals)
};await provider.request({
method: "dag_sendMetagraphTransaction",
params: [
{
metagraphAddress: "DAG0KheCYqEmFoQEWdFwrZGaXabJsWJyUvjpsLjE",
source: "DAG77zerQ2BUVhtVgkmseihkEfLXieBBm57vqA4J",
destination: "DAG2fMnbEmsWhgYGhvdREVELyESKUqGNTEWf4B61",
amount: 100000000,
fee: 0,
},
],
});
// "2d9fe9bad17debed7c903f22b74aac8af270daea7995dd099a58d6b201547169"type ChainId =
| "1" // Ethereum Mainnet
| "2" // Morden TestNet (deprecated)
| "3" // Ropsten TestNet
| "4" // Rinkeby TestNet
| "5" // Goerli TestNet
| "11155111"; // Sepolia TestNetawait provider.request({ method: "net_version", params: [] });
// "3"type WatchAssetParameters = {
type: String; // The token's interface. "L0" is the only supported type.
options: WatchAssetOptions;
};type WatchAssetOptions = {
chainId: Number; // The chain ID. 1 (mainnet), 3 (testnet), 4 (integrationnet)
address: Address; // Metagraph address
l0: String; // L0 endpoint
cl1: String; // Currency L1 endpoint
dl1: String; // Data L1 endpoint
name: String; // Name of the token
symbol: String; // Symbol of the token
logo: String; // Logo of the token
};await provider.request({
method: "eth_getBlockTransactionCountByHash",
params: [
"0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
],
});
// "0x50"await provider.request({ method: "eth_requestAccounts", params: [] });
// ["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]type ChainId =
| "1" // Ethereum Mainnet
| "2" // Morden Testnet (deprecated)
| "3" // Ropsten Testnet
| "4" // Rinkeby Testnet
| "5" // Goerli Testnet
| "11155111"; // Sepolia TestNetawait provider.request({ method: "net_version", params: [] });
// "3"WithdrawDelegatedStaketype WithdrawDelegatedStake = {
source: string; // Wallet address signing the transaction
stakeRef: string; // Reference to the delegated stake transaction
// Must be a valid delegated stake transaction hash
};await provider.request({
method: "dag_withdrawDelegatedStake",
params: [
{
source: 'DAG5sz69nNwGF8ypn1yukFpg2pVJpdx5mnf1PJVc',
stakeRef: '6c6ced4c67c931e71ecbe4bbf73462c1fe51522888620683e94faf7930a989da',
}
]
});
// "e041960eaea9d21760dc1c291e9ef96429e4cdbbeec2ffd504d4c2ebcc8cad45"type SignDataTransactionResponse = {
hash: string;
feeHash?: string;
signature: string;
feeSignature?: string;
};window.stargazer.getProvider("constellation");
// ChainProviderawait provider.request({ method: "dag_requestAccounts", params: [] });
// ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX"]provider.removeListener("accountsChanged", listener);const latestSnapshot = await dag4.network.l0Api.getLatestSnapshot();
const currentEpoch = latestSnapshot.value.epochProgress;await provider.request({
method: "dag_tokenLock",
params: [
{
source: 'DAG5sz69nNwGF8ypn1yukFpg2pVJpdx5mnf1PJVc',
amount: 100000000,
currencyId: 'DAG8RdiwFhZcLmjrsz79jiKfstQmPaSqABphCK1P',
fee: 0,
unlockEpoch: 1022060,
}
]
});
// "2d9fe9bad17debed7c903f22b74aac8af270daea7995dd099a58d6b201547169"provider.on("accountsChanged", () => {
// Do something when accounts changed
});if (window.stargazer) {
console.log("Stargazer version " + window.stargazer.version + " detected");
} else {
console.log("Stargazer not detected");
}const provider = window.stargazer.getProvider("constellation");await dagProvider.request({ method: "dag_requestAccounts", params: [] });
// ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX"] provider was activated
await ethProvider.request({ method: "eth_requestAccounts", params: [] });
// ["0xAab2C30c02016585EB36b7a0d5608Db787c1e44E"] provider was activatedconst activated = await provider.activate("A Cool App Name");const constellationProviderA = window.stargazer.getProvider("constellation");
const constellationProviderB = window.stargazer.getProvider("constellation");
const ethereumProviderA = window.stargazer.getProvider("ethereum");
const ethereumProviderB = window.stargazer.getProvider("ethereum");await provider.request({
method: "wallet_watchAsset",
params: [
{
type: "L0",
options: {
chainId: 4, // IntegrationNet
address: "DAG5kfY9GoHF1CYaY8tuRJxmB3JSzAEARJEAkA2C", // DOR Metagraph address
l0: "http://54.218.46.24:7000",
cl1: "http://54.218.46.24:8000",
dl1: "http://54.218.46.24:9000",
name: "IntegrationNet DOR",
symbol: "iDOR",
logo: "https://.../logo.png",
},
},
],
});
// trueawait provider.request({
method: "eth_getStorageAt",
params: [
"0x295a70b2de5e3953354a6a8344e616ed314d7251",
"0x6661e9d6d8b923d5bbaab1b96e1dd51ff6ea2a93520fdc9eb75d059238b8c5e9",
"0x65a8db",
],
});
// "0x0000000000000000000000000000000000000000000000000000000000000000"import * as ethers from "ethers";
const ethProvider = window.stargazer.getProvider("ethereum");
const ethersProvider = new ethers.providers.Web3Provider(ethProvider);// get balance from address
await ethersProvider.getBalance("0xEb14c9bb6C2DEc2eCb9B278C9fa1EC763B04d545");
// { BigNumber: "36428926959297445147" }// get current block number
await ethersProvider.getBlockNumber();
// 14983198// get current gas price
await ethersProvider.getGasPrice();
// { BigNumber: "23610503242" }import Web3 from "web3";
const ethProvider = window.stargazer.getProvider("ethereum");
const web3Provider = new Web3(ethProvider);// get balance from address
await web3Provider.eth.getBalance("0xEb14c9bb6C2DEc2eCb9B278C9fa1EC763B04d545");
// "36428926959297445147"// get current block number
await web3Provider.eth.getBlockNumber();
// 14983198// get current gas price
await web3Provider.eth.getGasPrice();
// "23610503242"await provider.request({
method: "dag_signMetagraphDataTransaction",
params: [
"DAG1ocZbNdp8GYAktqwjVyCRR1CpqaUQNi82gUwk",
{
MintCollection: {
name: "One collection"
}
}
],
});
// {
// hash: "2d9fe9bad17debed7c903f22b74aac8af270daea7995dd099a58d6b201547169",
// feeHash: "0a5feeeac5a0c62f776c9b4bd887c77caf495c331c94fa5d43d7a2bbf24e3ef1",
// signature: "3045022100b35798008516373fcc6eef75fe8e322ce8fe0dccc4802b052f3ddc7c6b5dc2900220154cac1e4f3e7d9a64f4ed9d2a518221b273fe782f037a5842725054f1c62280",
// feeSignature: "5432022100b35798008516373fcc6eef75fe8e322ce8fe0dccc4802b052f3ddc7c6b5dc2900220154cac1e4f3e7d9a64f4ed9d2a518221b273fe782f037a5842725054f1c62280"
// }type Transaction = {
hash: HexString<Hash>; // Hash of the transaction.
from: Address; // Address of the sender.
to: Address | null; // Address of the receiver or null for contract creations.
value: HexString<Number>; // Value sent in WEI.
blockHash: HexString<Hash> | null; // Block hash of transaction or null if transaction is pending.
blockNumber: HexString<Number> | null; // Block number of transaction or null if transaction is pending.
nonce: HexString<Number>; // Number of transactions made by the sender before.
gas: HexString<Number>; // Gas units provider by the sender.
gasPrice: HexString<Number>; // Gas price provider by the sender in WEI.
maxFeePerGas?: HexString<Number>; // Maximum fee in WEI per gas unit. EIP-1559.
maxPriorityFeePerGas?: HexString<Number>; // Maximum fee in WEI per gas unit above the base fee. EIP-1559.
input: HexString; // Data sent with the transaction.
r: HexString; // ECDSA signature r.
s: HexString; // ECDSA signature s.
v: HexString; // ECDSA recovery ID.
transactionIndex: HexString<Number> | null; // Transaction index in block or null if transaction is pending.
type: HexString<Number>; // Transaction type
};await provider.request({
method: "eth_getTransactionByHash",
params: [
"0xbb3a336e3f823ec18197f1e13ee875700f08f03e2cab75f0d0b118dabb44cba0",
],
});
/* {
blockHash:
"0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
blockNumber: "0x5bad55",
from: "0xfbb1b73c4f0bda4f67dca266ce6ef42f520fbb98",
gas: "0x249f0",
gasPrice: "0x174876e800",
hash: "0x8784d99762bccd03b2086eabccee0d77f14d05463281e121a62abfebcf0d2d5f",
input:
"0x6ea056a900000000000...",
nonce: "0x5e4724",
r: "0xd1556332df97e3bd911068651cfad6f975a30381f4ff3a55df7ab3512c78b9ec",
s: "0x66b51cbb10cd1b2a09aaff137d9f6d4255bf73cb7702b666ebd5af502ffa4410",
to: "0x4b9c25ca0224aef6a7522cabdbc3b2e125b7ca50",
transactionIndex: "0x0",
type: "0x0",
v: "0x25",
value: "0x0",
} */await provider.removeListenerAsync("accountsChanged", listener);await provider.request({
method: "dag_delegatedStake",
params: [
{
source: 'DAG5sz69nNwGF8ypn1yukFpg2pVJpdx5mnf1PJVc',
nodeId: '65b0c6ac3d0df47d7e7c275ac2d439d11dd73d67bca59cc9771ab7868d4a3e9e8a10661541932af394ca741765bd4d5807f030a3217553db75f050f7e65193fd',
amount: 100000000,
fee: 0,
tokenLockRef: '6c6ced4c67c931e71ecbe4bbf73462c1fe51522888620683e94faf7930a989da',
}
]
});
// "e041960eaea9d21760dc1c291e9ef96429e4cdbbeec2ffd504d4c2ebcc8cad45"type Transaction = {
from: Address // The account the transaction is sent from.
to?: Address // The transaction recipient.
gas?: Number ?? 90000 // Gas units provided for transaction executon. It will return unused gas.
gasPrice?: Number ?? currentGasPrice() // WEI paid for each gas unit used.
value?: Number // WEI sent with this transaction to the recipient.
data?: HexData // Encoded contract code or encoded contract call data.
}await provider.request({
method: "eth_getUncleCountByBlockNumber",
params: ["0x5bad55"],
});
// "0x1"provider.chain;
// "constellation"/**
* A base64 encoded string
* */
type Base64 = string;/**
* A JSON encoded string
* */
type JSONEncoded = string;type JSONScalarValue = null | string | number | boolean;type SignatureRequest = {
content: string;
metadata: Record<string, JSONScalarValue>;
};// Build the signature request
const signatureRequest: SignatureRequest = {
content: "Sign this message to confirm your address",
metadata: {
user: "3feb69d6-d3f0-4812-9c93-384bee08afe8",
},
};
// Encode the signature request - Base64 < JSON < Request
const signatureRequestEncoded = window.btoa(JSON.stringify(signatureRequest));
await provider.request({
method: "dag_signMessage",
params: ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX", signatureRequestEncoded],
});
// "3045022100b35798008516373fcc6eef75fe8e322ce8fe0dccc4802b052f3ddc7c6b5dc2900220154cac1e4f3e7d9a64f4ed9d2a518221b273fe782f037a5842725054f1c62280"// Build the same signature request
const signatureRequest: SignatureRequest = {
content: "Sign this message to confirm your address",
metadata: {
user: "3feb69d6-d3f0-4812-9c93-384bee08afe8",
},
};
// get the public key
const publicKey = await provider.request({
method: "dag_getPublicKey",
params: [
"DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX", // Your DAG address
],
});
// same request used in dag_signMessage
const signatureRequestEncoded = window.btoa(JSON.stringify(signatureRequest));
// hash returned by dag_signMessage in the pevious example
const signature =
"3045022100b35798008516373fcc6eef75fe8e322ce8fe0dccc4802b052f3ddc7c6b5dc2900220154cac1e4f3e7d9a64f4ed9d2a518221b273fe782f037a5842725054f1c62280";
const message = `\u0019Constellation Signed Message:\n${signatureRequestEncoded.length}\n${signatureRequestEncoded}`;
const result = await dag4.keyStore.verify(publicKey, message, signature);
// true -> verification succeeded
// false -> verification failedtype Transaction = {
from: Address // The account the transaction is sent from.
to?: Address // The transaction recipient.
gas?: Number ?? 90000 // Gas units provided for transaction executon. It will return unused gas.
gasPrice?: Number ?? currentGasPrice() // WEI paid for each gas unit used.
value?: Number // WEI sent with this transaction to the recipient.
data?: HexData // Encoded contract call data.
}await provider.request({
method: "eth_estimateGas",
params: [
{
from: "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
gas: "0x76c0",
gasPrice: "0x9184e72a000",
value: "0x9184e72a",
data: "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
},
],
});
// "0x5cec"type DelegatedStake = {
source: string; // Wallet address signing the transaction
nodeId: string; // The node identifier to delegate stake to
// Must be a valid node ID
amount: number; // The amount to stake
// Must be in DATUM
fee?: number; // The fee in DATUM
// If not provided, the default fee will be 0
tokenLockRef: string; // Reference to the token lock transaction
// Must be a valid token lock transaction hash
};await provider.request({
method: "eth_sendTransaction",
params: [
{
from: "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
gas: "0x76c0", // 30400
gasPrice: "0x9184e72a000", // 10000000000000
value: "0x9184e72a", // 2441406250
data: "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
},
],
});
// "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"await provider.request({
method: "eth_getBalance",
params: ["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"],
});
// "0x2fe84e3113d7b"await provider.request({
method: "eth_getTransactionCount",
params: ["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "0x5bad55"],
});
// "0x1a"await provider.request({
method: "personal_sign",
params: ["0xdeadbeaf", "0x9b2055d370f73ec7d8a03e965129118dc8f5bf83"],
});
// "0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b"dag_accounts RPC method and eth_accounts RPC method.npm install @stardust-collective/web3-react-stargazer-connectoryarn add @stardust-collective/web3-react-stargazer-connectorimport { StargazerWeb3ReactConnector } from "@stardust-collective/web3-react-stargazer-connector";
import { useWeb3React } from "@web3-react/core";
const stargazerConnector = new StargazerWeb3ReactConnector({
supportedChainIds: [1, 3],
});
function App() {
const { activate, active } = useWeb3React();
const connect = async () => {
try {
await activate(stargazerConnector);
} catch (ex) {
console.error(ex);
}
};
return (
<div>
<button onClick={connect}>{active ? "Connected" : "Connect"}</button>
</div>
);
}
export default App;npm install @stardust-collective/web3-react-stargazer-connectoryarn add @stardust-collective/web3-react-stargazer-connectorimport {stargazerWalletWagmiConnector} from '@stardust-collective/web3-react-stargazer-connector';
import { mainnet, polygon } from 'wagmi/chains'
import { createConfig, http, useConnect } from 'wagmi'
const stargazerConnector = stargazerWalletWagmiConnector();
declare module 'wagmi' {
interface Register {
config: typeof config
}
}
const config = createConfig({
chains: [mainnet, polygon],
transports: {
[mainnet.id]: http('[your rpc endpoint url]'),
[polygon.id]: http('[your rpc endpoint url]'),
},
connectors: [
stargazerWalletWagmiConnector({}),
...other wallet connectors
],
})
function App() {
const { connectors, connect } = useConnect()
const { address } = useAccount();
const doConnect = () => {
for(const connector of connectors){
if(connector.type === stargazerWalletWagmiConnector.type){
connect(connector);
}
}
}
return (
<div>
<button onClick={doConnect}>Connect Wallet</button>
{address && <p>Connected as {address}</p>}
</div>
);
}
export default App;npm install @stardust-collective/web3-react-stargazer-connectoryarn add @stardust-collective/web3-react-stargazer-connectorimport {useStargazerWallet} from '@stardust-collective/web3-react-stargazer-connector';
function App() {
const {activate, deactivate, ...state } = useStargazerWallet();
const doConnect = async () => {
await activate();
};
const doSignMessage = async () => {
if(!state.active){
return;
}
const signatureRequest = {
content: 'Sign this message to confirm your participation in this project.',
metadata: {
field1: 'an-useful-value',
field2: 1,
field3: null /* ,
field4: {
// Nested fields are not supported
prop:1
} */
}
};
// Encode the signature request - Base64 < JSON < Request
const signatureRequestEnconded = window.btoa(JSON.stringify(signatureRequest));
await state.request({
method: 'dag_signMessage',
params: [state.account, signatureRequestEnconded]
});
}
return (
<div>
<span>Connected To: {state.active && state.account}</span>
<button onClick={doConnect}>{state.active ? "Connected" : "Connect"}</button>
<button onClick={doSignMessage}>Sign Message</button>
</div>
);
}
export default App;type Log = {
address: Address; // Address from which this log was generated.
blockHash: HexString<Hash> | null; // Block hash from which this log was generated or null if transaction is pending.
blockNumber: HexString<Number> | null; // Block number from which this log was generated or null if transaction is pending.
transactionHash: HexString<Hash>; // Transaction hash from which this log was generated.
transactionIndex: HexString<Number> | null; // Transaction index from which this log was generated or null if transaction is pending.
data: HexString; // Data of non-indexed arguments for the log.
logIndex: HexString<Number> | null; // Log index in the block or null if transaction is pending.
removed: boolean; // True if the log was removed, due to a chain reorganization. False if it's a valid log.
topics: HexString<Topic>[]; // Array of 0 - 4 topics.
};await provider.request({
method: "eth_getFilterChanges",
params: ["0x10ff0bfbedb01f0dbd4106d14eb719ec38b6eb5b821c"],
});
/* [
{
address: "0x1a94fce7ef36bc90959e206ba569a12afbc91ca1",
blockHash:
"0x7c5a35e9cb3e8ae0e221ab470abae9d446c3a5626ce6689fc777dcffcab52c70",
blockNumber: "0x5c29fb",
data: "0x0000000000000000000000003e...",
logIndex: "0x1d",
removed: false,
topics: [
"0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80",
],
transactionHash:
"0x3dc91b98249fa9f2c5c37486a2427a3a7825be240c1c84961dfb3063d9c04d50",
transactionIndex: "0x1d",
},
{
address: "0x06012c8cf97bead5deae237070f9587f8e7a266d",
blockHash:
"0x7c5a35e9cb3e8ae0e221ab470abae9d446c3a5626ce6689fc777dcffcab52c70",
blockNumber: "0x5c29fb",
data: "0x0000000000000000000000007...",
logIndex: "0x57",
removed: false,
topics: [
"0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80",
],
transactionHash:
"0x788b1442414cb9c9a36dba2abe250763161a6f6395788a2e808f1b34e92beec1",
transactionIndex: "0x54",
},
] */type Log = {
address: Address; // Address from which this log was generated.
blockHash: HexString<Hash> | null; // Block hash from which this log was generated or null if transaction is pending.
blockNumber: HexString<Number> | null; // Block number from which this log was generated or null if transaction is pending.
transactionHash: HexString<Hash>; // Transaction hash from which this log was generated.
transactionIndex: HexString<Number> | null; // Transaction index from which this log was generated or null if transaction is pending.
data: HexString; // Data of non-indexed arguments for the log.
logIndex: HexString<Number> | null; // Log index in the block or null if transaction is pending.
removed: boolean; // True if the log was removed, due to a chain reorganization. False if it's a valid log.
topics: HexString<Topic>[]; // Array of 0 - 4 topics.
};await provider.request({
method: "eth_getFilterLogs",
params: ["0x10ff0bfbedb01f0dbd4106d14eb719ec38b6eb5b821c"],
});
/* [
{
address: "0xb5a5f22694352c15b00323844ad545abb2b11028",
blockHash:
"0x99e8663c7b6d8bba3c7627a17d774238eae3e793dee30008debb2699666657de",
blockNumber: "0x5d12ab",
data: "0x0000000000000000000000000000000000000000000000a247d7a2955b61d000",
logIndex: "0x0",
removed: false,
topics: [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000bdc0afe57b8e9468aa95396da2ab2063e595f37e",
"0x0000000000000000000000007503e090dc2b64a88f034fb45e247cbd82b8741e",
],
transactionHash:
"0xa74c2432c9cf7dbb875a385a2411fd8f13ca9ec12216864b1a1ead3c99de99cd",
transactionIndex: "0x3",
},
{
address: "0xe38165c9f6deb144afc9c32c206b024817e1496d",
blockHash:
"0x99e8663c7b6d8bba3c7627a17d774238eae3e793dee30008debb2699666657de",
blockNumber: "0x5d12ab",
data: "0x0000000000000000000000000000000000000000000000000000000025c6b720",
logIndex: "0x3",
removed: false,
topics: [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x00000000000000000000000080e73e47173b2d00b531bf83bc39e710157125c3",
"0x0000000000000000000000008f6cc93795969e5bbbf07c66dfee7d41ad24f1ef",
],
transactionHash:
"0x9e8f1cb1facb9a11a1cf947634053a0b2d557399f926b12127aa10497a2f0153",
transactionIndex: "0x5",
},
] */type Transaction = {
hash: HexString<Hash>; // Hash of the transaction.
from: Address; // Address of the sender.
to: Address | null; // Address of the receiver or null for contract creations.
value: HexString<Number>; // Value sent in WEI.
blockHash: HexString<Hash> | null; // Block hash of transaction or null if transaction is pending.
blockNumber: HexString<Number> | null; // Block number of transaction or null if transaction is pending.
nonce: HexString<Number>; // Number of transactions made by the sender before.
gas: HexString<Number>; // Gas units provider by the sender.
gasPrice: HexString<Number>; // Gas price provider by the sender in WEI.
maxFeePerGas?: HexString<Number>; // Maximum fee in WEI per gas unit. EIP-1559.
maxPriorityFeePerGas?: HexString<Number>; // Maximum fee in WEI per gas unit above the base fee. EIP-1559.
input: HexString; // Data sent with the transaction.
r: HexString; // ECDSA signature r.
s: HexString; // ECDSA signature s.
v: HexString; // ECDSA recovery ID.
transactionIndex: HexString<Number> | null; // Transaction index in block or null if transaction is pending.
type: HexString<Number>; // Transaction type
};await provider.request({
method: "eth_getTransactionByBlockHashAndIndex",
params: [
"0x5bad55",
"0x0",
],
});
/* {
blockHash:
"0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
blockNumber: "0x5bad55",
from: "0xfbb1b73c4f0bda4f67dca266ce6ef42f520fbb98",
gas: "0x249f0",
gasPrice: "0x174876e800",
hash: "0x8784d99762bccd03b2086eabccee0d77f14d05463281e121a62abfebcf0d2d5f",
input:
"0x6ea056a900000000000...",
nonce: "0x5e4724",
r: "0xd1556332df97e3bd911068651cfad6f975a30381f4ff3a55df7ab3512c78b9ec",
s: "0x66b51cbb10cd1b2a09aaff137d9f6d4255bf73cb7702b666ebd5af502ffa4410",
to: "0x4b9c25ca0224aef6a7522cabdbc3b2e125b7ca50",
transactionIndex: "0x0",
type: "0x0",
v: "0x25",
value: "0x0",
} */const dagProvider = window.stargazer.getProvider("constellation");
const ethProvider = window.stargazer.getProvider("ethereum");const dagAccounts = await dagProvider.request({ method: "dag_accounts" });
console.log(dagAccounts);
// ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX"]
const ethAccounts = await ethProvider.request({ method: "eth_accounts" });
console.log(eth_accounts);
// ["0x567d0382442c5178105fC03bd52b8Db6Afb4fE40"]import * as ethers from "ethers";
const ethersProvider = new ethers.providers.Web3Provider(ethProvider);
const StargazerGreeterAddress = "0x74299a718b2c44483a27325d7725f0b2646de3b1";
const StargazerGreeterABI = [...[]]; // You can get StargazerGreeter's ABI from https://sepolia.etherscan.io/address/0x74299a718b2c44483a27325d7725f0b2646de3b1#code;
const contract = new ethers.Contract(
StargazerGreeterAddress,
StargazerGreeterABI,
ethersProvider
);
await contract.greet();
// "Bon Matin!"import * as ethers from "ethers";
const ethersProvider = new ethers.providers.Web3Provider(ethProvider);
const signer = ethersProvider.getSigner();
const StargazerGreeterAddress = "0x74299a718b2c44483a27325d7725f0b2646de3b1";
const StargazerGreeterABI = [...[]]; // You can get StargazerGreeter's ABI from https://sepolia.etherscan.io/address/0x74299a718b2c44483a27325d7725f0b2646de3b1#code;
const contract = new ethers.Contract(
StargazerGreeterAddress,
StargazerGreeterABI,
signer
);
const greetingId = 1; // Bon Matin!
// We send a transaction to the network
const trxResponse = await contract.setGreeting(greetingId);
// We wait for confirmation
const trxReceipt = await library.waitForTransaction(trxResponse.hash);
console.log(trxReceipt.blockNumber);
// 12415408import * as ethers from "ethers";
const ethersProvider = new ethers.providers.Web3Provider(ethProvider);
const signer = ethersProvider.getSigner();
const StargazerSampleTokenAddress =
"0xfe9885baff18074846aaa2d5541581adf068731d";
const StargazerSampleTokenABI = [...[]]; // You can get StargazerSampleToken's ABI from https://sepolia.etherscan.io/address/0xfe9885baff18074846aaa2d5541581adf068731d#code;
const contract = new ethers.Contract(
StargazerSampleTokenAddress,
StargazerSampleTokenABI,
signer
);
const receiverAddress = "0x....";
const receiveValue = ethers.utils.parseUnits("10", 18).toHexString(); // 10 SST
// We send a transaction to the network
const trxResponse = await contract.transfer(receiverAddress, receiveValue);
// We wait for confirmation
const trxReceipt = await library.waitForTransaction(trxResponse.hash);
console.log(trxReceipt.blockNumber);
// 12415408import * as ethers from "ethers";
const ethersProvider = new ethers.providers.Web3Provider(ethProvider);
const signer = ethersProvider.getSigner();
const StargazerSampleTokenAddress =
"0xfe9885baff18074846aaa2d5541581adf068731d";
const StargazerSampleTokenABI = [...[]]; // You can get StargazerSampleToken's ABI from https://sepolia.etherscan.io/address/0xfe9885baff18074846aaa2d5541581adf068731d#code;
const contract = new ethers.Contract(
StargazerSampleTokenAddress,
StargazerSampleTokenABI,
signer
);
const spenderAddress = "0x....";
const spendValue = ethers.utils.parseUnits("10", 18).toHexString(); // 10 SST
// We send a transaction to the network
const trxResponse = await contract.approve(spenderAddress, spendValue);
// We wait for confirmation
const trxReceipt = await library.waitForTransaction(trxResponse.hash);
console.log(trxReceipt.blockNumber);
// 12415408import * as ethers from "ethers";
const ethersProvider = new ethers.providers.Web3Provider(ethProvider);
const oneGwei = ethers.BigNumber.from(1 * 1e9).toHexString();
const signer = ethersProvider.getSigner();
// We send a transaction to the network
const trxResponse = await signer.sendTransaction({
to: "0x....",
value: oneGwei,
});
// We wait for confirmation
const trxReceipt = await library.waitForTransaction(trxResponse.hash);
console.log(trxReceipt.blockNumber);
// 12415408type Block = {
number: HexString<Number> | null; // Block number or null if block is pending.
hash: HexString<Hash> | null; // Block hash or null if block is pending.
parentHash: HexString<Hash>; // Hash of the parent block.
nonce: HexString<Hash> | null; // Hash of the proof-of-work or null if block is pending.
sha3Uncles: HexString<Hash>; // SHA3 hash of the uncles data in the block.
logsBloom: HexString<FilterBloom> | null; // Bloom filter of the logs in the block or null if block is pending.
transactionsRoot: HexString<Hash>; // Root hash of the transaction trie of the block.
stateRoot: HexString<Hash>; // Root hash of the final state trie of the block.
receiptsRoot: HexString<Hash>; // Root hash of the receipts trie of the block.
miner: Address; // Miner's address for rewards.
difficulty: HexString<Number>; // Difficulty for this block.
totalDifficulty: HexString<Number>; // Total difficulty for the chain until this block.
extraData: HexString; // 32-byte long space to preserve for the ethernity :]
gasLimit: HexString<Number>; // Maximum gas allowed for this block.
gasUsed: HexString<Number>; // Total gas used for all transactions in this block.
size: HexString<Number>; // Size of this block in bytes.
timestamp: HexString<Number>; // The unix timestamp for when the block was collated.
transactions: Transaction[] | HexString<Hash>[]; // Array of transaction objects or transaction hashes.
uncles: HexString<Hash>[]; // Array of uncle hashes.
};type Transaction = {
hash: HexString<Hash>; // Hash of the transaction.
from: Address; // Address of the sender.
to: Address | null; // Address of the receiver or null for contract creations.
value: HexString<Number>; // Value sent in WEI.
blockHash: HexString<Hash> | null; // Block hash of transaction or null if transaction is pending.
blockNumber: HexString<Number> | null; // Block number of transaction or null if transaction is pending.
nonce: HexString<Number>; // Number of transactions made by the sender before.
gas: HexString<Number>; // Gas units provider by the sender.
gasPrice: HexString<Number>; // Gas price provider by the sender in WEI.
maxFeePerGas?: HexString<Number>; // Maximum fee in WEI per gas unit. EIP-1559.
maxPriorityFeePerGas?: HexString<Number>; // Maximum fee in WEI per gas unit above the base fee. EIP-1559.
input: HexString; // Data sent with the transaction.
r: HexString; // ECDSA signature r.
s: HexString; // ECDSA signature s.
v: HexString; // ECDSA recovery ID.
transactionIndex: HexString<Number> | null; // Transaction index in block or null if transaction is pending.
type: HexString<Number>; // Transaction type
};tyawait provider.request({
method: "eth_getBlockByNumber",
params: [
"0x5bad55",
],
});
/* {
difficulty: "0xbfabcdbd93dda",
extraData: "0x737061726b706f6f6c2d636e2d6e6f64652d3132",
gasLimit: "0x79f39e",
gasUsed: "0x79ccd3",
hash: "0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
logsBloom:
"0x4848112002a2020aaa081218004584...",
miner: "0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c",
nonce: "0x4db7a1c01d8a8072",
number: "0x5bad55",
parentHash:
"0x61a8ad530a8a43e3583f8ec163f773ad370329b2375d66433eb82f005e1d6202",
receiptsRoot:
"0x5eced534b3d84d3d732ddbc714f5fd51d98a941b28182b6efe6df3a0fe90004b",
sha3Uncles:
"0x8a562e7634774d3e3a36698ac4915e37fc84a2cd0044cb84fa5d80263d2af4f6",
size: "0x41c7",
stateRoot:
"0xf5208fffa2ba5a3f3a2f64ebd5ca3d098978bedd75f335f56b705d8715ee2305",
timestamp: "0x5b541449",
totalDifficulty: "0x12ac11391a2f3872fcd",
transactions: [
"0x8784d99762bccd03b2086eabccee0d77f14d05463281e121a62abfebcf0d2d5f",
"0x311be6a9b58748717ac0f70eb801d29973661aaf1365960d159e4ec4f4aa2d7f",
"0xe42b0256058b7cad8a14b136a0364acda0b4c36f5b02dea7e69bfd82cef252a2",
"0x4eb05376055c6456ed883fc843bc43df1dcf739c321ba431d518aecd7f98ca11",
"0x994dd9e72b212b7dc5fd0466ab75adf7d391cf4f206a65b7ad2a1fd032bb06d7",
...
],
transactionsRoot:
"0xf98631e290e88f58a46b7032f025969039aa9b5696498efc76baf436fa69b262",
uncles: [
"0x824cce7c7c2ec6874b9fa9a9a898eb5f27cbaf3991dfa81084c3af60d1db618c",
],
} */type TransactionReceipt = {
status: HexString<Number>; // 1 Success or 0 Failure
from: Address; // Address of the sender.
to: Address | null; // Address of the receiver or null for contract creations.
blockHash: HexString<Hash> | null; // Block hash of transaction or null if transaction is pending.
blockNumber: HexString<Number> | null; // Block number of transaction or null if transaction is pending.
contractAddress: Address | null; // Contract address created or null if no contract was created.
gasUsed: HexString<Number>; // Amount of gas units used by this transaction alone.
cumulativeGasUsed: HexString<Number>; // Amount of gas units used by this transaction in the block.
effectiveGasPrice: HexString<Number>; // Actual value per gas unit deducted from the sender's account.
transactionHash: HexString<Hash>; // Hash of the transaction.
transactionIndex: HexString<Number> | null; // Transaction index in block or null if transaction is pending.
type: HexString<Number>; // Transaction type
logs: Log[]; // Array of log objects generated from this transaction.
logsBloom: HexString<FilterBloom> | null; // Bloom filter of the logs generated from this transaction.
};type Log = {
address: Address; // Address from which this log was generated.
blockHash: HexString<Hash> | null; // Block hash from which this log was generated or null if transaction is pending.
blockNumber: HexString<Number> | null; // Block number from which this log was generated or null if transaction is pending.
transactionHash: HexString<Hash>; // Transaction hash from which this log was generated.
transactionIndex: HexString<Number> | null; // Transaction index from which this log was generated or null if transaction is pending.
data: HexString; // Data of non-indexed arguments for the log.
logIndex: HexString<Number> | null; // Log index in the block or null if transaction is pending.
removed: boolean; // True if the log was removed, due to a chain reorganization. False if it's a valid log.
topics: HexString<Topic>[]; // Array of 0 - 4 topics.
};await provider.request({
method: "eth_getTransactionReceipt",
params: [
"0xbb3a336e3f823ec18197f1e13ee875700f08f03e2cab75f0d0b118dabb44cba0",
],
});
/* {
blockHash:
"0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
blockNumber: "0x5bad55",
contractAddress: null,
cumulativeGasUsed: "0xb90b0",
effectiveGasPrice: "0x746a528800",
from: "0x398137383b3d25c92898c656696e41950e47316b",
gasUsed: "0x1383f",
logs: [
{
address: "0x06012c8cf97bead5deae237070f9587f8e7a266d",
blockHash:
"0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
blockNumber: "0x5bad55",
data: "0x000000000000000000000000...",
logIndex: "0x6",
removed: false,
topics: [
"0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80",
],
transactionHash:
"0xbb3a336e3f823ec18197f1e13ee875700f08f03e2cab75f0d0b118dabb44cba0",
transactionIndex: "0x11",
},
],
logsBloom: "0x000000000000000000000000000000...",
status: "0x1",
to: "0x06012c8cf97bead5deae237070f9587f8e7a266d",
transactionHash:
"0xbb3a336e3f823ec18197f1e13ee875700f08f03e2cab75f0d0b118dabb44cba0",
transactionIndex: "0x11",
type: "0x0",
} */type PendingTransactionParams = {
metagraphAddress: String; // Metagraph address
hash: String; // Hash of the transaction
};type Request = {
readonly method: string;
readonly params?: any[];
};await provider.request({ method: "eth_accounts", params: [] });
// ["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]type PendingTransaction = {
transaction: {
source: Address; // Address of the sender
destination: Address; // Address of the receiver
amount: Number; // Amount sent
fee: Number; // Fee sent
parent: {
hash: String<Hash>; // Hash of the parent transaction
ordinal: Number; // Ordinal of the parent transaction
};
salt: BigNumber | String; // Salt
};
hash: String<Hash>; // Hash of the transaction
status: String; // Status of the transaction. Currently there is only one status: "Waiting"
};await provider.request({
method: "dag_getMetagraphPendingTransaction",
params: [
{
metagraphAddress: "DAG0KheCYqEmFoQEWdFwrZGaXabJsWJyUvjpsLjE",
hash: "3826c2848a477ff40e3ae27d5b9f99bd2d4a30cd2702873a740dc7c77792310a",
},
],
});
// {
// "transaction": {
// "source": "DAG77zerQ2BUVhtVgkmseihkEfLXieBBm57vqA4J",
// "destination": "DAG2fMnbEmsWhgYGhvdREVELyESKUqGNTEWf4B61",
// "amount": 100000000,
// "fee": 0,
// "parent": {
// "ordinal": 31,
// "hash": "8d521fa8590151bebb5bf47b5436a93c054486955390d84cf6844cdea275426a"
// },
// "salt": 8837683016871549
// },
// "hash": "3826c2848a477ff40e3ae27d5b9f99bd2d4a30cd2702873a740dc7c77792310a",
// "status": "Waiting"
// }
await provider.request({ method: "dag_accounts", params: [] });
// ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX"]await provider.request({
method: "eth_getCode",
params: ["0x06012c8cf97bead5deae237070f9587f8e7a266d"],
});
// "0x60606040..."await provider.request({
method: "web3_sha3",
params: ["0x68656c6c6f20776f726c64"],
});
// "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"type SendDataTransactionResponse = {
hash: string;
feeHash?: string;
};await provider.request({
method: "eth_getUncleCountByBlockHash",
params: [
"0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
],
});
// "0x1"await provider.request({
method: "eth_getBlockTransactionCountByNumber",
params: ["0x5bad55"],
});
// "0x50"type TransactionParams = {
metagraphAddress: String; // Metagraph address
hash: String; // Hash of the transaction
};type Filter = {
address?: Address; // Address from which logs generated.
fromBlock?: HexString<Number> | "latest" | "earliest" | "pending"; // Block number or string the string "latest", "earliest" or "pending" to search from.
toBlock?: HexString<Number> | "latest" | "earliest" | "pending"; // Block number or string the string "latest", "earliest" or "pending" to search to.
topics?: HexString<Topic>[]; // Array of 0 - 4 topics.
blockHash?: HexString<Hash>; // Block from which logs generated.
};await provider.request({
method: "eth_newFilter",
params: [
{
topics: [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
],
},
],
});
// "0x10ff0bfba9472c87932c56632eef8f5cc70910e8e71d"await provider.request({
method: "dag_sendMetagraphDataTransaction",
params: [
"DAG1ocZbNdp8GYAktqwjVyCRR1CpqaUQNi82gUwk",
{
MintCollection: {
name: "One collection"
}
}
],
});
// {
// hash: "2d9fe9bad17debed7c903f22b74aac8af270daea7995dd099a58d6b201547169",
// feeHash: "0a5feeeac5a0c62f776c9b4bd887c77caf495c331c94fa5d43d7a2bbf24e3ef1"
// }type PendingTransaction = {
transaction: {
source: Address // Address of the sender
destination: Address // Address of the receiver
amount: Number // Amount sent in DATUM
fee: Number // Fee sent in DATUM
parent: {
hash: String<Hash> // Hash of the parent transaction
ordinal: Number // Ordinal of the parent transaction
}
salt: BigNumber | String // Salt
}
hash: String<Hash> // Hash of the transaction
status: String // Status of the transaction. Currently there is only one status: "Waiting"
}await provider.request({
method: "dag_getPendingTransaction",
params: [
"3826c2848a477ff40e3ae27d5b9f99bd2d4a30cd2702873a740dc7c77792310a"
],
});
// {
// "transaction": {
// "source": "DAG77zerQ2BUVhtVgkmseihkEfLXieBBm57vqA4J",
// "destination": "DAG2fMnbEmsWhgYGhvdREVELyESKUqGNTEWf4B61",
// "amount": 100000000,
// "fee": 0,
// "parent": {
// "ordinal": 31,
// "hash": "8d521fa8590151bebb5bf47b5436a93c054486955390d84cf6844cdea275426a"
// },
// "salt": 8837683016871549
// },
// "hash": "3826c2848a477ff40e3ae27d5b9f99bd2d4a30cd2702873a740dc7c77792310a",
// "status": "Waiting"
// }
type Transaction = {
hash: String<Hash>; // Hash of the transaction
amount: Number; // Amount sent
source: Address; // Address of the sender
destination: Address; // Address of the receiver
fee: Number; // Fee sent
parent: {
hash: String<Hash>; // Hash of the parent transaction
ordinal: Number; // Ordinal of the parent transaction
};
blockHash: String<Hash>; // Hash of the block
snapshotHash: String<Hash>; // Hash of the snapshot
snapshotOrdinal: Number; // Ordinal of the snapshot
transactionOriginal: {
value: {
source: Address; // Address of the sender
destination: Address; // Address of the receiver
amount: Number; // Amount sent
fee: Number; // Fee sent
parent: {
hash: String<Hash>; // Hash of the parent transaction
ordinal: Number; // Ordinal of the parent transaction
};
salt: BigNumber | String; // Salt
};
proofs: Proof[]; // Proofs
};
timestamp: String; // Timestamp
};type Proof = {
id: String; // Id of the signature
signature: String; // Signature
};await provider.request({
method: "dag_getMetagraphTransaction",
params: [
{
metagraphAddress: "DAG0KheCYqEmFoQEWdFwrZGaXabJsWJyUvjpsLjE",
hash: "233af0219d6a956aae0839c18ce95470dc2ac0645aa3135a22be608c06e7713e",
},
],
});
// {
// "hash": "233af0219d6a956aae0839c18ce95470dc2ac0645aa3135a22be608c06e7713e",
// "amount": 300000000,
// "source": "DAG77zerQ2BUVhtVgkmseihkEfLXieBBm57vqA4J",
// "destination": "DAG2fMnbEmsWhgYGhvdREVELyESKUqGNTEWf4B61",
// "fee": 0,
// "parent": {
// "hash": "9ef0cd77c91abe5dac643f0ada9e51af20a30c38b2b2cf7b8793a5955d5c9485",
// "ordinal": 4
// },
// "blockHash": "dad7482866af8d9f44c2b309d263add3b4c2c8e6063a36910783a42fe2bd5509",
// "snapshotHash": "d22a21946e0b257a489212b30a593274798892be2ef6a02b8d8218abc8a5f0ae",
// "snapshotOrdinal": 34233,
// "transactionOriginal": {
// "value": {
// "source": "DAG77zerQ2BUVhtVgkmseihkEfLXieBBm57vqA4J",
// "destination": "DAG2fMnbEmsWhgYGhvdREVELyESKUqGNTEWf4B61",
// "amount": 300000000,
// "fee": 0,
// "parent": {
// "ordinal": 4,
// "hash": "9ef0cd77c91abe5dac643f0ada9e51af20a30c38b2b2cf7b8793a5955d5c9485"
// },
// "salt": 8792229999094409
// },
// "proofs": [
// {
// "id": "b85cbc0d210bfb98de58b9b1c6d195f6ee09e254e489f284756e3ebae82054823b04e64bcc62bb6b20ee8016b819419389037d8d09e278e47fe79645cfd8b166",
// "signature": "30450221009a66b5a64998df405c40e5eb6b4ad42e3e4f7b31d70071e866c045ef58dc1f9b022048a66d373e241bc10f917f11832eccf6244b255c68c11c6ee1e7f442068ae613"
// }
// ]
// },
// "timestamp": "2023-06-29T18:38:00.412Z"
// }type Transaction = {
from: Address // The account the transaction is sent from.
to?: Address // The transaction recipient.
gas?: Number ?? 90000 // Gas units provided for transaction executon. It will return unused gas.
gasPrice?: Number ?? currentGasPrice() // WEI paid for each gas unit used.
value?: Number // WEI sent with this transaction to the recipient.
data?: HexData // Encoded contract call data.
}await provider.request({
method: "eth_call",
params: [
{
from: "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
gas: "0x76c0", // 30400
gasPrice: "0x9184e72a000", // 10000000000000
value: "0x9184e72a", // 2441406250
data: "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
},
"latest",
],
});
// "0x9184e8f"await provider.request({
method: "eth_uninstallFilter",
params: ["0x10ff0bfba9472c87932c56632eef8f5cc70910e8e71d"],
});
// truetype Filter = {
address?: Address; // Address from which logs generated.
fromBlock?: HexString<Number> | "latest" | "earliest" | "pending"; // Block number or string the string "latest", "earliest" or "pending" to search from.
toBlock?: HexString<Number> | "latest" | "earliest" | "pending"; // Block number or string the string "latest", "earliest" or "pending" to search to.
topics?: HexString<Topic>[]; // Array of 0 - 4 topics.
blockHash?: HexString<Hash>; // Block from which logs generated.
};type Log = {
address: Address; // Address from which this log was generated.
blockHash: HexString<Hash> | null; // Block hash from which this log was generated or null if transaction is pending.
blockNumber: HexString<Number> | null; // Block number from which this log was generated or null if transaction is pending.
transactionHash: HexString<Hash>; // Transaction hash from which this log was generated.
transactionIndex: HexString<Number> | null; // Transaction index from which this log was generated or null if transaction is pending.
data: HexString; // Data of non-indexed arguments for the log.
logIndex: HexString<Number> | null; // Log index in the block or null if transaction is pending.
removed: boolean; // True if the log was removed, due to a chain reorganization. False if it's a valid log.
topics: HexString<Topic>[]; // Array of 0 - 4 topics.
};await provider.request({
method: "eth_getLogs",
params: [
{
blockHash:
"0x7c5a35e9cb3e8ae0e221ab470abae9d446c3a5626ce6689fc777dcffcab52c70",
topics: [
"0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80",
],
},
],
});
/* [
{
address: "0x1a94fce7ef36bc90959e206ba569a12afbc91ca1",
blockHash:
"0x7c5a35e9cb3e8ae0e221ab470abae9d446c3a5626ce6689fc777dcffcab52c70",
blockNumber: "0x5c29fb",
data: "0x0000000000000000000000003e...",
logIndex: "0x1d",
removed: false,
topics: [
"0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80",
],
transactionHash:
"0x3dc91b98249fa9f2c5c37486a2427a3a7825be240c1c84961dfb3063d9c04d50",
transactionIndex: "0x1d",
},
{
address: "0x06012c8cf97bead5deae237070f9587f8e7a266d",
blockHash:
"0x7c5a35e9cb3e8ae0e221ab470abae9d446c3a5626ce6689fc777dcffcab52c70",
blockNumber: "0x5c29fb",
data: "0x0000000000000000000000007...",
logIndex: "0x57",
removed: false,
topics: [
"0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80",
],
transactionHash:
"0x788b1442414cb9c9a36dba2abe250763161a6f6395788a2e808f1b34e92beec1",
transactionIndex: "0x54",
},
] */type Transaction = {
hash: HexString<Hash>; // Hash of the transaction.
from: Address; // Address of the sender.
to: Address | null; // Address of the receiver or null for contract creations.
value: HexString<Number>; // Value sent in WEI.
blockHash: HexString<Hash> | null; // Block hash of transaction or null if transaction is pending.
blockNumber: HexString<Number> | null; // Block number of transaction or null if transaction is pending.
nonce: HexString<Number>; // Number of transactions made by the sender before.
gas: HexString<Number>; // Gas units provider by the sender.
gasPrice: HexString<Number>; // Gas price provider by the sender in WEI.
maxFeePerGas?: HexString<Number>; // Maximum fee in WEI per gas unit. EIP-1559.
maxPriorityFeePerGas?: HexString<Number>; // Maximum fee in WEI per gas unit above the base fee. EIP-1559.
input: HexString; // Data sent with the transaction.
r: HexString; // ECDSA signature r.
s: HexString; // ECDSA signature s.
v: HexString; // ECDSA recovery ID.
transactionIndex: HexString<Number> | null; // Transaction index in block or null if transaction is pending.
type: HexString<Number>; // Transaction type
};await provider.request({
method: "eth_getTransactionByBlockHashAndIndex",
params: [
"0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
"0x0",
],
});
/* {
blockHash:
"0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
blockNumber: "0x5bad55",
from: "0xfbb1b73c4f0bda4f67dca266ce6ef42f520fbb98",
gas: "0x249f0",
gasPrice: "0x174876e800",
hash: "0x8784d99762bccd03b2086eabccee0d77f14d05463281e121a62abfebcf0d2d5f",
input:
"0x6ea056a900000000000...",
nonce: "0x5e4724",
r: "0xd1556332df97e3bd911068651cfad6f975a30381f4ff3a55df7ab3512c78b9ec",
s: "0x66b51cbb10cd1b2a09aaff137d9f6d4255bf73cb7702b666ebd5af502ffa4410",
to: "0x4b9c25ca0224aef6a7522cabdbc3b2e125b7ca50",
transactionIndex: "0x0",
type: "0x0",
v: "0x25",
value: "0x0",
} */provider.version;
// "3.5.2"type Block = {
number: HexString<Number> | null; // Block number or null if block is pending.
hash: HexString<Hash> | null; // Block hash or null if block is pending.
parentHash: HexString<Hash>; // Hash of the parent block.
nonce: HexString<Hash> | null; // Hash of the proof-of-work or null if block is pending.
sha3Uncles: HexString<Hash>; // SHA3 hash of the uncles data in the block.
logsBloom: HexString<FilterBloom> | null; // Bloom filter of the logs in the block or null if block is pending.
transactionsRoot: HexString<Hash>; // Root hash of the transaction trie of the block.
stateRoot: HexString<Hash>; // Root hash of the final state trie of the block.
receiptsRoot: HexString<Hash>; // Root hash of the receipts trie of the block.
miner: Address; // Miner's address for rewards.
difficulty: HexString<Number>; // Difficulty for this block.
totalDifficulty: HexString<Number>; // Total difficulty for the chain until this block.
extraData: HexString; // 32-byte long space to preserve for the ethernity :]
gasLimit: HexString<Number>; // Maximum gas allowed for this block.
gasUsed: HexString<Number>; // Total gas used for all transactions in this block.
size: HexString<Number>; // Size of this block in bytes.
timestamp: HexString<Number>; // The unix timestamp for when the block was collated.
transactions: Transaction[] | HexString<Hash>[]; // Array of transaction objects or transaction hashes.
uncles: HexString<Hash>[]; // Array of uncle hashes.
};type Transaction = {
hash: HexString<Hash>; // Hash of the transaction.
from: Address; // Address of the sender.
to: Address | null; // Address of the receiver or null for contract creations.
value: HexString<Number>; // Value sent in WEI.
blockHash: HexString<Hash> | null; // Block hash of transaction or null if transaction is pending.
blockNumber: HexString<Number> | null; // Block number of transaction or null if transaction is pending.
nonce: HexString<Number>; // Number of transactions made by the sender before.
gas: HexString<Number>; // Gas units provider by the sender.
gasPrice: HexString<Number>; // Gas price provider by the sender in WEI.
maxFeePerGas?: HexString<Number>; // Maximum fee in WEI per gas unit. EIP-1559.
maxPriorityFeePerGas?: HexString<Number>; // Maximum fee in WEI per gas unit above the base fee. EIP-1559.
input: HexString; // Data sent with the transaction.
r: HexString; // ECDSA signature r.
s: HexString; // ECDSA signature s.
v: HexString; // ECDSA recovery ID.
transactionIndex: HexString<Number> | null; // Transaction index in block or null if transaction is pending.
type: HexString<Number>; // Transaction type
};await provider.request({
method: "eth_getBlockByHash",
params: ["0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35"],
});
/* {
difficulty: "0xbfabcdbd93dda",
extraData: "0x737061726b706f6f6c2d636e2d6e6f64652d3132",
gasLimit: "0x79f39e",
gasUsed: "0x79ccd3",
hash: "0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
logsBloom:
"0x4848112002a2020aaa081218004584...",
miner: "0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c",
nonce: "0x4db7a1c01d8a8072",
number: "0x5bad55",
parentHash:
"0x61a8ad530a8a43e3583f8ec163f773ad370329b2375d66433eb82f005e1d6202",
receiptsRoot:
"0x5eced534b3d84d3d732ddbc714f5fd51d98a941b28182b6efe6df3a0fe90004b",
sha3Uncles:
"0x8a562e7634774d3e3a36698ac4915e37fc84a2cd0044cb84fa5d80263d2af4f6",
size: "0x41c7",
stateRoot:
"0xf5208fffa2ba5a3f3a2f64ebd5ca3d098978bedd75f335f56b705d8715ee2305",
timestamp: "0x5b541449",
totalDifficulty: "0x12ac11391a2f3872fcd",
transactions: [
"0x8784d99762bccd03b2086eabccee0d77f14d05463281e121a62abfebcf0d2d5f",
"0x311be6a9b58748717ac0f70eb801d29973661aaf1365960d159e4ec4f4aa2d7f",
"0xe42b0256058b7cad8a14b136a0364acda0b4c36f5b02dea7e69bfd82cef252a2",
"0x4eb05376055c6456ed883fc843bc43df1dcf739c321ba431d518aecd7f98ca11",
"0x994dd9e72b212b7dc5fd0466ab75adf7d391cf4f206a65b7ad2a1fd032bb06d7",
...
],
transactionsRoot:
"0xf98631e290e88f58a46b7032f025969039aa9b5696498efc76baf436fa69b262",
uncles: [
"0x824cce7c7c2ec6874b9fa9a9a898eb5f27cbaf3991dfa81084c3af60d1db618c",
],
} */// https://eips.ethereum.org/EIPS/eip-712#parameters
type MessagePayload = {
domain: EIP712Domain;
types: { EIP712Domain: EIP712Domain } & Record<string, TypedProperty[]>;
primaryType: string;
message: any;
};
// https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator
type EIP712Domain = {
name?: string;
version?: string;
chainId?: Number<uint256>;
verifyingContract?: Address;
salt?: HexString<bytes32>;
};
// https://eips.ethereum.org/EIPS/eip-712#definition-of-typed-structured-data-%F0%9D%95%8A
type TypedProperty = {
name: string;
type: string;
};await provider.request({
method: "eth_signTypedData",
params: [
"0x567d0382442c5178105fC03bd52b8Db6Afb4fE40",
{
types: {
DeviceControl: [
{
name: "principal",
type: "AuthorizedEntity",
},
{
name: "emergency",
type: "AuthorizedEntity",
},
],
AuthorizedEntity: [
{
name: "address",
type: "address",
},
{
name: "validUntil",
type: "uint256",
},
],
EIP712Domain: [
{
name: "name",
type: "string",
},
{
name: "version",
type: "string",
},
{
name: "chainId",
type: "uint256",
},
{
name: "verifyingContract",
type: "address",
},
],
},
domain: {
name: "Stargazer Demo",
version: "1.0.0",
chainId: "3",
verifyingContract: "0xeb14c9bb6c2dec2ecb9b278c9fa1ec763b04d545",
},
primaryType: "DeviceControl",
message: {
principal: {
address: "0xeb14c9bb6c2dec2ecb9b278c9fa1ec763b04d545",
validUntil: "1657823568",
},
emergency: {
address: "0xcac3da343670abb46bc6e8e6d375b66217519093",
validUntil: "1752517998",
},
},
},
],
});
// "0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b"type UncleBlock = {
number: HexString<Number> | null; // Block number or null if block is pending.
hash: HexString<Hash> | null; // Block hash or null if block is pending.
parentHash: HexString<Hash>; // Hash of the parent block.
nonce: HexString<Hash> | null; // Hash of the proof-of-work or null if block is pending.
sha3Uncles: HexString<Hash>; // SHA3 hash of the uncles data in the block.
logsBloom: HexString<FilterBloom> | null; // Bloom filter of the logs in the block or null if block is pending.
transactionsRoot: HexString<Hash>; // Root hash of the transaction trie of the block.
stateRoot: HexString<Hash>; // Root hash of the final state trie of the block.
receiptsRoot: HexString<Hash>; // Root hash of the receipts trie of the block.
miner: Address; // Miner's address for rewards.
difficulty: HexString<Number>; // Difficulty for this block.
totalDifficulty: HexString<Number>; // Total difficulty for the chain until this block.
extraData: HexString; // 32-byte long space to preserve for the ethernity :]
gasLimit: HexString<Number>; // Maximum gas allowed for this block.
gasUsed: HexString<Number>; // Total gas used for all transactions in this block.
size: HexString<Number>; // Size of this block in bytes.
timestamp: HexString<Number>; // The unix timestamp for when the block was collated.
uncles: HexString<Hash>[]; // Array of uncle hashes.
};await provider.request({
method: "eth_getUncleByBlockNumberAndIndex",
params: ["0x29c", "0x0"],
});
/* {
difficulty: "0xbfabcdbd93dda",
extraData: "0x737061726b706f6f6c2d636e2d6e6f64652d3132",
gasLimit: "0x79f39e",
gasUsed: "0x79ccd3",
hash: "0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
logsBloom:
"0x4848112002a2020aaa081218004584...",
miner: "0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c",
nonce: "0x4db7a1c01d8a8072",
number: "0x5bad55",
parentHash:
"0x61a8ad530a8a43e3583f8ec163f773ad370329b2375d66433eb82f005e1d6202",
receiptsRoot:
"0x5eced534b3d84d3d732ddbc714f5fd51d98a941b28182b6efe6df3a0fe90004b",
sha3Uncles:
"0x8a562e7634774d3e3a36698ac4915e37fc84a2cd0044cb84fa5d80263d2af4f6",
size: "0x41c7",
stateRoot:
"0xf5208fffa2ba5a3f3a2f64ebd5ca3d098978bedd75f335f56b705d8715ee2305",
timestamp: "0x5b541449",
totalDifficulty: "0x12ac11391a2f3872fcd",
transactionsRoot:
"0xf98631e290e88f58a46b7032f025969039aa9b5696498efc76baf436fa69b262",
uncles: []
} */
/**
* A base64 encoded string
* */
type Base64 = string;/**
* A JSON encoded string
* */
type JSONEncoded = string;/**
* A String encoded
* */
type StringEncoded = string;// Build the signature request
const signatureRequest: any = {
field1: "content_field_1",
field2: {
field2_1: true,
field2_2: 12332435,
field2_3: {
field2_3_1: "content_field2_3_1",
},
},
field3: [1, 2, 3, 4],
field4: null,
};
// Encode the signature request - Base64 < JSON < Request
const signatureRequestEncoded = window.btoa(JSON.stringify(signatureRequest));
// Encode the string directly if "signatureRequest" is a string:
// const signatureRequest = "This is a custom string.";
//
// Base64 < String
// const signatureRequestEncoded = window.btoa(signatureRequest);
await provider.request({
method: "dag_signData",
params: ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX", signatureRequestEncoded],
});
// "3045022100b35798008516373fcc6eef75fe8e322ce8fe0dccc4802b052f3ddc7c6b5dc2900220154cac1e4f3e7d9a64f4ed9d2a518221b273fe782f037a5842725054f1c62280"// Build the same signature request
const signatureRequest: any = {
field1: "content_field_1",
field2: {
field2_1: true,
field2_2: 12332435,
field2_3: {
field2_3_1: "content_field2_3_1",
},
},
field3: [1, 2, 3, 4],
field4: null,
};
// get the public key
const publicKey = await provider.request({
method: "dag_getPublicKey",
params: [
"DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX", // Your DAG address
],
});
// same request used in dag_signData
const signatureRequestEncoded = window.btoa(JSON.stringify(signatureRequest));
// hash returned by dag_signData in the pevious example
const signature =
"3045022100b35798008516373fcc6eef75fe8e322ce8fe0dccc4802b052f3ddc7c6b5dc2900220154cac1e4f3e7d9a64f4ed9d2a518221b273fe782f037a5842725054f1c62280";
const message = `\u0019Constellation Signed Data:\n${signatureRequestEncoded.length}\n${signatureRequestEncoded}`;
const result = await dag4.keyStore.verifyData(publicKey, message, signature);
// true -> verification succeeded
// false -> verification failedtype UncleBlock = {
number: HexString<Number> | null; // Block number or null if block is pending.
hash: HexString<Hash> | null; // Block hash or null if block is pending.
parentHash: HexString<Hash>; // Hash of the parent block.
nonce: HexString<Hash> | null; // Hash of the proof-of-work or null if block is pending.
sha3Uncles: HexString<Hash>; // SHA3 hash of the uncles data in the block.
logsBloom: HexString<FilterBloom> | null; // Bloom filter of the logs in the block or null if block is pending.
transactionsRoot: HexString<Hash>; // Root hash of the transaction trie of the block.
stateRoot: HexString<Hash>; // Root hash of the final state trie of the block.
receiptsRoot: HexString<Hash>; // Root hash of the receipts trie of the block.
miner: Address; // Miner's address for rewards.
difficulty: HexString<Number>; // Difficulty for this block.
totalDifficulty: HexString<Number>; // Total difficulty for the chain until this block.
extraData: HexString; // 32-byte long space to preserve for the ethernity :]
gasLimit: HexString<Number>; // Maximum gas allowed for this block.
gasUsed: HexString<Number>; // Total gas used for all transactions in this block.
size: HexString<Number>; // Size of this block in bytes.
timestamp: HexString<Number>; // The unix timestamp for when the block was collated.
uncles: HexString<Hash>[]; // Array of uncle hashes.
};await provider.request({
method: "eth_getUncleByBlockHashAndIndex",
params: [
"0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
"0x0",
],
});
/* {
difficulty: "0xbfabcdbd93dda",
extraData: "0x737061726b706f6f6c2d636e2d6e6f64652d3132",
gasLimit: "0x79f39e",
gasUsed: "0x79ccd3",
hash: "0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
logsBloom:
"0x4848112002a2020aaa081218004584...",
miner: "0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c",
nonce: "0x4db7a1c01d8a8072",
number: "0x5bad55",
parentHash:
"0x61a8ad530a8a43e3583f8ec163f773ad370329b2375d66433eb82f005e1d6202",
receiptsRoot:
"0x5eced534b3d84d3d732ddbc714f5fd51d98a941b28182b6efe6df3a0fe90004b",
sha3Uncles:
"0x8a562e7634774d3e3a36698ac4915e37fc84a2cd0044cb84fa5d80263d2af4f6",
size: "0x41c7",
stateRoot:
"0xf5208fffa2ba5a3f3a2f64ebd5ca3d098978bedd75f335f56b705d8715ee2305",
timestamp: "0x5b541449",
totalDifficulty: "0x12ac11391a2f3872fcd",
transactionsRoot:
"0xf98631e290e88f58a46b7032f025969039aa9b5696498efc76baf436fa69b262",
uncles: []
} */const dagProvider = window.stargazer.getProvider("constellation");
const ethProvider = window.stargazer.getProvider("ethereum");// Build the signature request
const signatureRequest: SignatureRequest = {
content: "Sign this message to confirm your address",
metadata: {
user: "3feb69d6-d3f0-4812-9c93-384bee08afe8",
},
};// Encode the signature request - Base64 < JSON < Request
const signatureRequestEnconded = window.btoa(JSON.stringify(signatureRequest));// Send the request and wait for the signature
await dagProvider.request({
method: "dag_signMessage",
params: [
"DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX",
signatureRequestEnconded,
],
});
// "3045022100b35798008516373fcc6eef75fe8e322ce8fe0dccc4802b052f3ddc7c6b5dc2900220154cac1e4f3e7d9a64f4ed9d2a518221b273fe782f037a5842725054f1c62280"// Send the request and wait for the signature
await dagProvider.request({
method: "dag_getPublicKey",
params: ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX"],
});
// "0482c4566a9c4cbb6f23b9a31c96876501c71f5c04b35f416e0b2243113cce8fb386a2db0b3881d1c908d33465748b948649165a6705904120238999eed6eed1f4"// Send the request and wait for the signature
await dagProvider.request({
method: "personal_sign",
params: [
"0x5369676e2074686973206d65737361676520746f20636f6e6669726d20796f7572206164647265737320616e64207573657249642033666562363964362d643366302d343831322d396339332d333834626565303861666538",
"0x9b2055d370f73ec7d8a03e965129118dc8f5bf83",
],
});
// "0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b"
// Can also be a valid UTF-8 string
await dagProvider.request({
method: "personal_sign",
params: [
"Sign this message to confirm your address and userId 3feb69d6-d3f0-4812-9c93-384bee08afe8",
"0x9b2055d370f73ec7d8a03e965129118dc8f5bf83",
],
});
// "0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b"await provider.request({
method: "eth_signTypedData",
params: [
"0x567d0382442c5178105fC03bd52b8Db6Afb4fE40",
{
types: {
DeviceControl: [
{
name: "principal",
type: "AuthorizedEntity",
},
{
name: "emergency",
type: "AuthorizedEntity",
},
],
AuthorizedEntity: [
{
name: "address",
type: "address",
},
{
name: "validUntil",
type: "uint256",
},
],
EIP712Domain: [
{
name: "name",
type: "string",
},
{
name: "version",
type: "string",
},
{
name: "chainId",
type: "uint256",
},
{
name: "verifyingContract",
type: "address",
},
],
},
domain: {
name: "Stargazer Demo",
version: "1.0.0",
chainId: "3",
verifyingContract: "0xeb14c9bb6c2dec2ecb9b278c9fa1ec763b04d545",
},
primaryType: "DeviceControl",
message: {
principal: {
address: "0xeb14c9bb6c2dec2ecb9b278c9fa1ec763b04d545",
validUntil: "1657823568",
},
emergency: {
address: "0xcac3da343670abb46bc6e8e6d375b66217519093",
validUntil: "1752517998",
},
},
},
],
});
// "0xa3f20717a250c2b0b729b7e5becbff67fdaef7e0699da4de7ca5895b02a170a12d887fd3b17bfdce3481f10bea41f45ba9f709d39ce8325427b57afcfc994cee1b"import { dag4 } from "@stardust-collective/dag4";
const publicKey = "account-public-key";
const signatureRequestEnconded = "the-base64-encoded-signature-request";
const signatureHex = "some-hex-encoded-signature";
const valid: boolean = dag4.keyStore.verify(
publicKey,
signatureRequestEnconded,
signatureHex
);
const publicKeyAddress = dag4.keyStore.getDagAddressFromPublicKey(publicKey);import * as ethers from "ethers";
const accountWhichSigned = "0x9b2055d370f73ec7d8a03e965129118dc8f5bf83";
const messageSigned = "some-message-the-user-signed";
const signatureHex = "some-hex-encoded-signature";
const messageHash = ethers.utils.hashMessage(messageSigned);
const recoveredAddress = ethers.utils.recoverAddress(messageHash, signatureHex);
if (recoveredAddress !== accountWhichSigned) {
throw new Error("Signature is not valid");
}import * as ethers from "ethers";
const accountWhichSigned = "0x9b2055d370f73ec7d8a03e965129118dc8f5bf83";
const messageSigned = {
// The EIP-712 domain signed
domain: {
name: "Stargazer Demo",
version: "1.0.0",
chainId: 3,
verifyingContract: "0xabcdefABCDEF1234567890abcdefABCDEF123456",
},
// The EIP-712 types signed
types: {
DeviceControl: [
{ name: "principal", type: "AuthorizedEntity" },
{ name: "emergency", type: "AuthorizedEntity" },
],
AuthorizedEntity: [
{ name: "address", type: "address" },
{ name: "validUntil", type: "uint256" },
],
},
// The EIP-712 message signed
value: {
principal: {
address: "0xEb14c9bb6C2DEc2eCb9B278C9fa1EC763B04d545",
validUntil: 1657823568,
},
emergency: {
address: "0xcAc3DA343670aBB46BC6E8e6d375B66217519093",
validUntil: 1752517998,
},
},
};
const signatureHex = "some-hex-encoded-signature";
const messageHash = ethers.utils._TypedDataEncoder.hash(
messageSigned.domain,
messageSigned.types,
messageSigned.value
);
const recoveredAddress = ethers.utils.recoverAddress(messageHash, signatureHex);
if (recoveredAddress !== accountWhichSigned) {
throw new Error("Signature is not valid");
}await provider.activate();
// trueawait provider.request({
method: "eth_newBlockFilter",
params: [],
});
// "0x81440bfbd6138ec9fe6d6ec4398b0b4879fb182f3cd8"const latestSnapshot = await dag4.network.l0Api.getLatestSnapshot();
const currentEpoch = latestSnapshot.value.epochProgress;type AllowSpend = {
source: string; // Wallet address signing the transaction
destination: string; // The destination address
// Must be a metagraph address
amount: number; // The amount to allow spend
// Must be in DATUM
approvers: string[]; // An array with a single DAG address that can atomically approve this operation
// Can be a metagraph or wallet address
currencyId: string | null; // The currency metagraph identifier
// For DAG, this field must be null
fee?: number; // The fee in the currency of the currency metagraph, or DAG.
// If not provided, the default fee will be 0
// Must be in DATUM
validUntilEpoch?: number; // The global snapshot epoch progress for which this is valid until
// If not provided, the default value will be currentEpoch + 30
// Minumum allowed value: currentEpoch + 5
// Maximum allowed value: currentEpoch + 60
};await provider.request({
method: "dag_allowSpend",
params: [
{
source: 'DAG5sz69nNwGF8ypn1yukFpg2pVJpdx5mnf1PJVc',
destination: 'DAG3miCyHnvuoyywvnvnMzt35Y9Gs7EqTHQx6xtg',
amount: 100000000,
approvers: ['DAG3miCyHnvuoyywvnvnMzt35Y9Gs7EqTHQx6xtg'],
currencyId: 'DAG8RdiwFhZcLmjrsz79jiKfstQmPaSqABphCK1P',
fee: 0,
validUntilEpoch: 1022060,
}
]
});
// "2d9fe9bad17debed7c903f22b74aac8af270daea7995dd099a58d6b201547169"type Proof = {
id: String // Id of the signature
signature: String // Signature
}type Transaction = {
hash: String<Hash> // Hash of the transaction
amount: Number // Amount sent in DATUM
source: Address // Address of the sender
destination: Address // Address of the receiver
fee: Number // Fee sent in DATUM
parent: {
hash: String<Hash> // Hash of the parent transaction
ordinal: Number // Ordinal of the parent transaction
}
blockHash: String<Hash> // Hash of the block
snapshotHash: String<Hash> // Hash of the snapshot
snapshotOrdinal: Number // Ordinal of the snapshot
transactionOriginal: {
value: {
source: Address // Address of the sender
destination: Address // Address of the receiver
amount: Number // Amount sent in DATUM
fee: Number // Fee sent in DATUM
parent: {
hash: String<Hash> // Hash of the parent transaction
ordinal: Number // Ordinal of the parent transaction
}
salt: BigNumber | String // Salt
}
proofs: Proof[] // Proofs
}
timestamp: String // Timestamp
}await provider.request({
method: "dag_getTransaction",
params: [
"5659d17c234d57c57a7335792889fe50cf66ec3d717b5d28d9bfa943e4275d27"
],
});
// {
// "hash": "5659d17c234d57c57a7335792889fe50cf66ec3d717b5d28d9bfa943e4275d27",
// "amount": 100000000,
// "source": "DAG77zerQ2BUVhtVgkmseihkEfLXieBBm57vqA4J",
// "destination": "DAG2fMnbEmsWhgYGhvdREVELyESKUqGNTEWf4B61",
// "fee": 0,
// "parent": {
// "hash": "3826c2848a477ff40e3ae27d5b9f99bd2d4a30cd2702873a740dc7c77792310a",
// "ordinal": 32
// },
// "blockHash": "f2df30d776dbf05240b14654d2e156099b25ff6e45084eac9ab89c37689a2007",
// "snapshotHash": "f41437fc5fc01483069e8d11ff3597f4c2715f44a859432d3f0041838ff270d2",
// "snapshotOrdinal": 509453,
// "transactionOriginal": {
// "value": {
// "source": "DAG77zerQ2BUVhtVgkmseihkEfLXieBBm57vqA4J",
// "destination": "DAG2fMnbEmsWhgYGhvdREVELyESKUqGNTEWf4B61",
// "amount": 100000000,
// "fee": 0,
// "parent": {
// "ordinal": 32,
// "hash": "3826c2848a477ff40e3ae27d5b9f99bd2d4a30cd2702873a740dc7c77792310a"
// },
// "salt": 8888012531929986
// },
// "proofs": [
// {
// "id": "b85cbc0d210bfb98de58b9b1c6d195f6ee09e254e489f284756e3ebae82054823b04e64bcc62bb6b20ee8016b819419389037d8d09e278e47fe79645cfd8b166",
// "signature": "3045022100e597cb6ac5e05e00c03998c11ed4ee0c3d8e42aedd37c19f4968ad494d5357e202205f754fe64410e2d8770b3976eb458c4bd3b22aa8f48609c2577dab88e23ef3fd"
// }
// ]
// },
// "timestamp": "2023-01-26T15:42:21.970Z"
// }