41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
const express = require('express');
|
|
|
|
require('dotenv').config();
|
|
|
|
const app = express();
|
|
const port = process.env.PORT || 3000;
|
|
|
|
const {
|
|
CasperClient, DeployUtil, Contracts: { Contract },
|
|
} = require('casper-js-sdk');
|
|
|
|
const RPC_API = 'http://65.109.56.30:7777/rpc';
|
|
|
|
const casperClient = new CasperClient(RPC_API);
|
|
const contract = new Contract(casperClient);
|
|
contract.setContractHash('hash-9d6641378c5859e4a0367b37f358d9861496318ba814bdd92903210a3f633198');
|
|
|
|
app.use(express.json());
|
|
|
|
app.post('/sendDeploy', async (req, res) => {
|
|
const { body: deployJson } = req;
|
|
const deploy = DeployUtil.deployFromJson(deployJson).unwrap();
|
|
const deployHash = await casperClient.putDeploy(deploy);
|
|
res.status(200).send(`Deploy hash: ${deployHash}`);
|
|
});
|
|
|
|
app.get('/queryMessage', async (req, res) => {
|
|
const result = await contract.queryContractData(['message']);
|
|
console.log('query result:', result);
|
|
res.send(result);
|
|
});
|
|
|
|
app.get('*', (req, res) => {
|
|
console.log(`req.path: ${req.path}`);
|
|
res.send('Hello World!');
|
|
});
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Example app listening on port ${port}`);
|
|
});
|