Facing error on deploying contract in Binance Smart Chain - blockchain

I am trying to deploy a test contract on Binance Smart Chain network. I am using metamask, and truffle to create and test the contract. My folder structure looks like this
const HDWalletProvider = require('truffle-hdwallet-provider-privkey');
const privateKeys = process.env.PRIVATE_KEYS || ""
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*"
},
binancetestnet: {
provider: function() {
return new HDWalletProvider(
privateKeys.split(','), // Array of account private keys
`https://data-seed-prebsc-1-s1.binance.org:8545/${process.env.INFURA_API_KEY}`// Url to an Ethereum Node
)
},
gas: 5000000,
gasPrice: 25000000000,
network_id: 97
}
},
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},
// Configure your compilers
compilers: {
solc: {
version: "0.7.3", // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
// enabled: false,
// runs: 200
// },
// evmVersion: "byzantium"
// }
}
}
};
Truffle Deployment Error
Macbook-Air Oracle % truffle migrate --reset --network binancetestnet
Error: Cannot find module 'truffle-hdwallet-provider-privkey'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/Users/macbbok/Desktop/Oracle/truffle-config.js:1:26)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at Object.require (internal/modules/cjs/helpers.js:25:18)
at Function.load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/config/dist/index.js:161:1)
at Function.detect (/usr/local/lib/node_modules/truffle/build/webpack:/packages/config/dist/index.js:150:1)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:199:1)
at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:136:1)
at Object.module.exports (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/cli.js:56:1)
at __webpack_require__ (/usr/local/lib/node_modules/truffle/build/webpack:/webpack/bootstrap:19:1)
at /usr/local/lib/node_modules/truffle/build/webpack:/webpack/bootstrap:83:1
at Object.<anonymous> (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:89:10)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Truffle v5.1.54 (core: 5.1.54)
Node v10.16.3
I have attached all the code with errors I am facing. Can anyone help me with it?
I have also Installed the HD Wallet provider as well. Truffle compile worked successfully.

After Installing Truffle HD wallet provider
Now Facing
MacBook-Air Test % truffle migrate --reset --network binancetestnet
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Error: Could not create addresses from your mnemonic or private key(s). Please check that your inputs are correct.
at new HDWalletProvider (/Users/macbook/Desktop/Test/node_modules/#truffle/hdwallet-provider/src/index.ts:124:13)
at Object.provider (/Users/macbook/Desktop/Test/truffle-config.js:12:16)
at Object.getProvider (/usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:20:1)
at Object.create (/usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/index.js:13:1)
at TruffleConfig.get [as provider] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/config/dist/configDefaults.js:200:1)
at Object.detect (/usr/local/lib/node_modules/truffle/build/webpack:/packages/environment/environment.js:19:1)
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:206:1
Truffle v5.1.54 (core: 5.1.54)
Node v14.15.4
My Truffle.js code
const HDWalletProvider = require('#truffle/hdwallet-provider');
const privateKeys = process.env.PRIVATE_KEYS || ""
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*"
},
binancetestnet: {
provider: function() {
return new HDWalletProvider(
privateKeys.split(','), // Array of account private keys
`https://data-seed-prebsc-1-s1.binance.org:8545/${process.env.INFURA_API_KEY}`// Url to an Ethereum Node
)
},
gas: 5000000,
gasPrice: 25000000000,
network_id: 97
}
},
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},
// Configure your compilers
compilers: {
solc: {
version: "0.7.3", // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
// enabled: false,
// runs: 200
// },
// evmVersion: "byzantium"
// }
}
}
};
My .env file
ETHERSCAN_API_KEY=https://data-seed-prebsc-1-s1.binance.org:8545/
INFURA_API_KEY=https://data-seed-prebsc-1-s1.binance.org:8545/
PRIVATE_KEYS="9xxxxx3fb486a57ad13e6db71xxxxx456e4128d51ecxxxxxxxd"
DEV_ADDRESS="0xxxxxxe80e3a43EBCab9A6CeC9d9e2a49100AxxxC"

I faced similar problem, and found the solution to use private key instead of mnemonic:
in your .env :
API_URL = "https://ropsten.infura.io/v3/your project id" # note: put your node url here
PRIVATE_KEY = "your account private key"
and in your truffle-config.js:
module.exports= {
....
rospten: {
provider: () => new HDWalletProvider(
process.env.PRIVATE_KEY,
process.env.API_URL),
network_id: 3,
gas: 1000000,
gasPrice: 20000000000,
confirmations: 2,
timeoutBlocks: 200000,
}
....
}

Related

migration run out of gas

Hi I am using Geth and i try to truffle migrate but it gives error.
truffle-config.js is belown:
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "4", //rinkeby id
from:"my address",
gas: 1000
}
When I do truffle migrate using command -truffle migrate, I get this error.
Error: Error: Error: *** Deployment Failed ***
"Migrations" ran out of gas (using a value you set in your network
config or deployment parameters.)
* Block limit: 0x50e7c
* Gas sent: 1000
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-migrate/index.js:92:1)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Can you help me please?
I solved the error by adding this code to the truffle config file.
compilers: {
solc: {
version: "0.5.16",
settings: {
optimizer: {
enabled: true, // Default: false
runs: 1000, // Default: 200
},
},
},
},
It's exactly what the error says.
ran out of gas (using a value you set in your network
config or deployment parameters.)
gas: 1000 is not enough to deploy your contract

Creation of CfnWebACL for rate based rule fails (AWS CDK WAF Regional)

I am trying to setup a rate based rule using AWS CDK (#aws-cdk/aws-wafregional v1.4.0).
This is my very simple JavaScript-setup:
const cdk = require('#aws-cdk/core');
const waf = require('#aws-cdk/aws-wafregional');
class TstStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const rule = new waf.CfnRateBasedRule(this, 'rule', {
metricName: `rateRule`,
name: 'rate-rule',
rateKey: 'IP',
rateLimit: 2010
});
const acl = new waf.CfnWebACL(this, 'acl', {
defaultAction: { type: 'ALLOW' },
metricName: 'rateAcl',
name: 'rate-acl',
rules: [{
action: { type: 'BLOCK' },
priority: 1,
ruleId: rule.ref
}]
});
}
}
module.exports = { TstStack }
To create the rule is no problem. But the stack creation fails on the Web ACL. The error message is:
The referenced item does not exist. (Service: AWSWAFRegional; Status Code: 400; Error Code: WAFNonexistentItemException
What am I missing here, why is it not possible to create the CfnWebACL-object?
For reference, the complete output:
3/4 | 9:49:31 PM | CREATE_FAILED | AWS::WAFRegional::WebACL | acl The referenced item does not exist. (Service: AWSWAFRegional; Status Code: 400; Error Code: WAFNonexistentItemException; Request ID: e4d897ef-c138-11e9-bf23-fb4702c5a89a)
new TstStack (/app/infrastructure/apps/tst/lib/tst-stack.js:16:21)
\_ Object.<anonymous> (/app/infrastructure/apps/tst/bin/tst.js:9:1)
\_ Module._compile (internal/modules/cjs/loader.js:778:30)
\_ Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
\_ Module.load (internal/modules/cjs/loader.js:653:32)
\_ tryModuleLoad (internal/modules/cjs/loader.js:593:12)
\_ Function.Module._load (internal/modules/cjs/loader.js:585:3)
\_ Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
\_ startup (internal/bootstrap/node.js:283:19)
\_ bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
This aggravated me for a while also. I finally saw the following in the CloudFormation documentation for the rate-rules:
Note you can only create rate-based rules using a CloudFormation template. To add the rate-based rules created through CloudFormation to a web ACL, use the AWS WAF console, API, or command line interface (CLI). For more information, see UpdateWebACL.
Basically, you can create the rule, but you can't associate it with an ACL through AWS CloudFormation.

Claudia.js create cannot find module lambda in typescript project

After searching for hours I can't figure out how to properly run claudia create in my project.
Following this turoial, I created a group and a user the AWS console, then I added the keys to my .aws/credentials file.
Then I ran this command that correctly produced the lambda.js file :
claudia --source dist generate-serverless-express-proxy --express-module app
My lambda.js
'use strict'
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const binaryMimeTypes = [
'application/octet-stream',
'font/eot',
'font/opentype',
'font/otf',
'image/jpeg',
'image/png',
'image/svg+xml'
]
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context)
Then I tried to deploy the lambda function on AWS :
claudia create --source dist --profile myprofile --handler lambda.handler --deploy-proxy-api --region eu-west-1
But I got this error :
validating package TypeError: "listener" argument must be a function
at _addListener (events.js:239:11)
at Server.addListener (events.js:297:10)
at new Server (_http_server.js:269:10)
at Object.createServer (http.js:34:10)
at Object.createServer (/tmp/IiRPif/my-project-1.0.0-1Yh6Wb/package/node_modules/aws-serverless-express/index.js:155:25)
at Object. (/tmp/IiRPif/my-project-1.0.0-1Yh6Wb/package/lambda.js:13:37)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at validatePackage (/usr/local/lib/node_modules/claudia/src/tasks/validate-package.js:16:15)
at initEnvVarsFromOptions.then.then.then.then.then.then.then.dir (/usr/local/lib/node_modules/claudia/src/commands/create.js:342:10)
at cannot require ./lambda after clean installation. Check your dependencies.
What am I doing wrong here ?
My package.json
{
"name": "...",
"version": "1.0.0",
"scripts": {
"build": "tsc -p tsconfig.json & cp \"package.json\" \"dist/package.json\"
},
"repository": {
"type": "git",
"url": "..."
},
"homepage": "...",
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.3",
"mongoose": "^5.2.7",
"nodemon": "^1.18.3"
},
"devDependencies": {
"typescript": "^3.0.1"
}
}
My app.ts
import * as express from "express";
import * as bodyParser from "body-parser";
import * as mongoose from "mongoose";
import { Routes } from "./routes/routes";
class App {
public app: express.Application;
public routes: Routes = new Routes();
constructor() {
this.app = express();
// Parser setup
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({ extended: true }));
this.routes.routes(this.app);
}
}
exports.default = new App().app;
After a discussion on Claudia's github, this appears to be a compatibility issue between es6 and claudia/lambda.
All I needed to do was to change this line in my app.js file from :
exports.default = new App().app;
To :
module.exports = new App().app;

Cloud Functions: Detailed stack trace: Error: Cannot find module 'googleapis'

This is related to these 2 threads:
Google cloud functions - cannot read property 'getApplicationDefault'
Triggering Cloud Dataflow pipeline from Cloud Function - function times out
I have created a dataflow template that will copy data from GCS to BigQuery as these two examples.
As part of the initialization process, I run
npm init
npm install --save googleapis
Here is my index.js
var {google} = require('googleapis');
exports.goWithTheDataFlow = (event, callback) => {
const file = event.data;
const context = event.context;
console.log(`Event ${context.eventId}`);
console.log(` Event Type: ${context.eventType}`);
console.log(` Bucket: ${file.bucket}`);
console.log(` File: ${file.name}`);
console.log(` Metageneration: ${file.metageneration}`);
console.log(` Created: ${file.timeCreated}`);
console.log(` Updated: ${file.updated}`);
google.auth.getApplicationDefault(function (err, authClient, projectId) {
if (err) {
throw err;
}
console.log(projectId);
const dataflow = google.dataflow({ version: 'v1b3', auth: authClient });
console.log(`gs://${file.bucket}/${file.name}`);
dataflow.projects.templates.create({
projectId: projectId,
resource: {
parameters: {
inputFile: `gs://${file.bucket}/${file.name}`
},
jobName: 'cloud-fn-beam-test',
gcsPath: 'gs://goldsgymdemo/templates/MyGCStoBQDFTemplate'
}
}, function(err, response) {
if (err) {
console.error("problem running dataflow template, error was: ", err);
}
console.log("Dataflow template response: ", response);
callback();
});
});
callback();
};
And here is my package.json (after I have run npm init & npm install --save googleapis)
{
"name": "sample-cloud-storage",
"version": "0.0.1"
}
When I run this function with function: goWithTheDataFlow & Trigger:
I get an error:
Deployment failure:
Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'googleapis'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/index.js:1:78)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
Can you please help? What am I missing?
Thx
You are missing dependencies in your package.json file. Add googleapis dependency to it:
{
"name": "sample-cloud-storage",
"version": "0.0.1",
"dependencies": {
"googleapis": "^21.3.0"
}
}
It worked for me when I changed directory into the functions folder, instead of the firebase project folder and did a package install in there
cd functions
npm install [your missing package] --save
in my case, I accidentally use devDependecy module in a file that uploaded to Firebase.
for example, in my User model class I use a property or method from this dependency
import * as firebase from "#firebase/rules-unit-testing";
but in the package.json file, that dependcy is located in devDependecy like this
"devDependencies": {
"#firebase/rules-unit-testing": "^1.3.14",
},
devDependencies will not deployed to the server, thats why I have "Can't find module" error

Error deploying meteor app on aws

Here is the mup.js:
module.exports = {
servers: {
one: {
host: '52.41.186.122',
username: 'ubuntu',
pem: 'aws-key/xanthelabs.pem'
// password:
// or leave blank for authenticate from ssh-agent
}
},
meteor: {
name: 'deep-app',
path: '/home/cortana/Desktop/deep-app',
servers: {
one: {}
},
buildOptions: {
serverOnly: true,
},
env: {
ROOT_URL: 'http://52.41.186.122:8888',
MONGO_URL: 'mongodb://localhost/meteor'
},
//dockerImage: 'kadirahq/meteord'
deployCheckWaitTime: 60
},
mongo: {
oplog: true,
port: 27017,
servers: {
one: {},
},
},
};
The error is:
Started TaskList: Start Meteor
[52.41.186.122] - Start Meteor
[52.41.186.122] - Start Meteor: SUCCESS
[52.41.186.122] - Verifying Deployment
[52.41.186.122] x Verifying Deployment: FAILED
-----------------------------------STDERR-----------------------------------
npm WARN deprecated semver behavior.
npm WARN package.json meteor-dev-bundle#0.0.0 No description
npm WARN package.json meteor-dev-bundle#0.0.0 No repository field.
npm WARN package.json meteor-dev-bundle#0.0.0 No README data
npm WARN cannot run in wd meteor-dev-bundle#0.0.0 node npm-rebuild.js (wd=/bundle/bundle/programs/server)
=> Starting meteor app on port:80
assert.js:93
throw new assert.AssertionError({
^
AssertionError: "undefined" === "function"
at wrapPathFunction (/bundle/bundle/programs/server/mini-files.js:77:10)
at Object.<anonymous> (/bundle/bundle/programs/server/mini-files.js:108:24)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/bundle/bundle/programs/server/boot.js:9:13)
at Module._compile (module.js:456:26)
-----------------------------------STDOUT-----------------------------------
To see more logs type 'mup logs --tail=50'
----------------------------------------------------------------------------
(node:8968) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error:
-----------------------------------STDERR-----------------------------------
npm WARN deprecated semver behavior.
npm WARN package.json meteor-dev-bundle#0.0.0 No description
npm WARN package.json meteor-dev-bundle#0.0.0 No repository field.
npm WARN package.json meteor-dev-bundle#0.0.0 No README data
npm WARN cannot run in wd meteor-dev-bundle#0.0.0 node npm-rebuild.js (wd=/bundle/bundle/programs/server)
=> Starting meteor app on port:80
assert.js:93
throw new assert.AssertionError({
^
AssertionError: "undefined" === "function"
at wrapPathFunction (/bundle/bundle/programs/server/mini-files.js:77:10)
at Object.<anonymous> (/bundle/bundle/programs/server/mini-files.js:108:24)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/bundle/bundle/programs/server/boot.js:9:13)
at Module._compile (module.js:456:26)
-----------------------------------STDOUT-----------------------------------
To see more logs type 'mup logs --tail=50'
----------------------------------------------------------------------------
Everything has been successfully setup. I dont understand what is throwing the error. Please explain the error and its reasons along with the solution. Thanks
About the system:
OS: ubuntu 16.04
deployment OS: Ubuntu 14.04 (on aws)
meteor : v1.4.1.2
Edit:
On using meteor-up fork suggested, I am getting this error:
[52.41.186.122] - Installing Node.js
[52.41.186.122] - Installing Node.js: SUCCESS
[52.41.186.122] - Installing PhantomJS
[52.41.186.122] - Installing PhantomJS: SUCCESS
[52.41.186.122] - Setting up Environment
[52.41.186.122] - Setting up Environment: SUCCESS
[52.41.186.122] - Copying MongoDB configuration
[52.41.186.122] x Copying MongoDB configuration: FAILED
Received exit code 0 while establishing SFTP session
The mup.js file I have is:
{
// Server authentication info
"servers": [
{
"host": "52.41.186.122",
"username": "ubuntu",
// "password": "ubuntu"
// or pem file (ssh based authentication)
"pem": "aws-key/xanthelabs.pem"
}
],
// Install MongoDB in the server, does not destroy local MongoDB on future setup
"setupMongo": true,
// WARNING: Node.js is required! Only skip if you already have Node.js installed on server.
"setupNode": true,
// WARNING: If nodeVersion omitted will setup 0.10.43 by default. Do not use v, only version number.
"nodeVersion": "4.4.7",
// Install PhantomJS in the server
"setupPhantom": true,
// Show a progress bar during the upload of the bundle to the server.
// Might cause an error in some rare cases if set to true, for instance in Shippable CI
"enableUploadProgressBar": true,
// Application name (No spaces)
"appName": "deep-app",
// Location of app (local directory)
"app": "/home/cortana/Desktop/deep-app",
// Configure environment
"env": {
"PORT": 8888,
"ROOT_URL": "http://52.41.186.122",
"MONGO_URL": "mongodb://localhost/meteor"
},
// Meteor Up checks if the app comes online just after the deployment
// before mup checks that, it will wait for no. of seconds configured below
"deployCheckWaitTime": 15
}
what is wrong here?
i had the same issues. add dockerImage: "abernix/meteord:base", to you meteor part of MUP.json.
If it's still not working. replace Flow Router with React Router