Skip to content

Commit

Permalink
feat: add tezos taquito
Browse files Browse the repository at this point in the history
  • Loading branch information
Pianochicken committed Aug 23, 2023
1 parent 9b69e99 commit 2d4a537
Show file tree
Hide file tree
Showing 5 changed files with 421 additions and 109 deletions.
25 changes: 25 additions & 0 deletions packages/tezos-interact/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "tezos-interact",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsup src/index.ts --format cjs --dts",
"build:dev": "npm run build -- --watch",
"dev": "ts-node src/test.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@taquito/signer": "^17.2.0",
"@taquito/taquito": "^17.2.0",
"ts-node": "^10.9.1",
"tsconfig": "workspace:*",
"tsup": "^6.1.3"
},
"devDependencies": {
"tsconfig": "workspace:*",
"typescript": "^5.1.6"
}
}
59 changes: 59 additions & 0 deletions packages/tezos-interact/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { TezosToolkit } from '@taquito/taquito';
import { InMemorySigner, importKey } from '@taquito/signer';

const Tezos = new TezosToolkit('https://ghostnet.tezos.marigold.dev');

Tezos.setProvider({
signer: new InMemorySigner('edskS1zsQPHwdhuQQ9dcvtmrgSC1f7pqMZMrst4xzB4hMgkmAzgnDHbRhHGckG7RXN6yoed1PE31S63z2Y7Pa13kvZcQgcQ8bU'),
});


export const accessProposal = async () => {
await Tezos.contract
.at('KT1KqDtnTZMYiEpe81f6u24Jnmq5Hg2h9z5v')
.then((contract) => {
console.log('Access proposal...')
return contract.methods.access().send();
})
.then((op) => {
const result: any = op.results[0]
console.log(`Waiting for ${op.hash} to be confirmed...`);
return op.confirmation(1).then(() => op.hash);
})
.then((hash) => {
console.log(`Access operation finished: https://better-call.dev/ghostnet/opg/${hash}`)
})
.catch((error) => {
console.log(`Access error: ${JSON.stringify(error, null, 2)}`)
})
}

export const voteProposal = async (vote: number) => {
await Tezos.contract
.at('KT1KqDtnTZMYiEpe81f6u24Jnmq5Hg2h9z5v')
.then((contract) => {
console.log('Vote proposal...')
return contract.methods.vote(vote).send();
})
.then((op) => {
console.log(`Waiting for ${op.hash} to be confirmed...`);
return op.confirmation(1).then(() => op.hash);
})
.then((hash) => {
console.log(`Vote finished: https://better-call.dev/ghostnet/opg/${hash}`)
})
.catch((error) => {
console.log(`Vote error: ${JSON.stringify(error, null, 2)}`)
});
}

export const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))

const main = async () => {
// await voteProposal(1)
// sleep(15000)
// await accessProposal()
}

main()

8 changes: 8 additions & 0 deletions packages/tezos-interact/src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { voteProposal, accessProposal } from './index';

const main = async () => {
await voteProposal(1)
await accessProposal()
}

main()
8 changes: 8 additions & 0 deletions packages/tezos-interact/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "tsconfig/base.json",
"compilerOptions": {
"target": "ESNext",
},
"include": [ "**/*.ts"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 2d4a537

Please sign in to comment.