/
index.ts
45 lines (37 loc) · 1.14 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Masa } from '@masa-finance/masa-sdk';
import { ethers, Wallet } from 'ethers';
const config = {
...process.env,
};
const envs = {
dev: 'https://dev.middleware.masa.finance/',
beta: 'https://beta.middleware.masa.finance/',
test: 'https://test.middleware.masa.finance/',
local: 'http://localhost:4000/',
};
export const createRandomWallet = (): Wallet => {
console.info("Creating random wallet!");
const wallet = ethers.Wallet.createRandom();
wallet.connect(
new ethers.providers.JsonRpcProvider("https://rpc.ankr.com/eth_goerli")
);
return wallet;
};
export const createNewMasa = (
newWallet,
env: 'dev' | 'beta' | 'test' | 'local' = 'dev'
) => {
const signer = newWallet ? newWallet : createRandomWallet()
return new Masa({
cookie: config.cookie || undefined,
wallet: signer,
apiUrl: envs[env],
environment: config.environment || 'dev',
arweave: {
host: config['arweave-host'] || 'arweave.net',
port: parseInt(config?.['arweave-port'] || '443'),
protocol: config['arweave-protocol'] || 'https',
logging: (!!config['arweave-logging'] as boolean) || false,
},
});
};